Register
It is currently Tue Sep 30, 2014 1:52 pm

string replace


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Mar 08, 2010 2:32 pm   

Joined: Mon Mar 08, 2010 2:26 pm
Posts: 2
I'd like to write output to a file but would need to replace illegal characters in a string first.

the output filename includes filesystem labels from df.

what can i add to replace the illegal characters?

Code:
#!/bin/sh
#http://www.ibm.com/developerworks/aix/library/au-satdiskmon.html#N10278

warninglimit=500000
lowlimit=250000

filesystems="/export/data /export/home /"

for fs in $filesystems
do
        size=`df -k $fs|grep $fs|awk '{ print $4; }'`
        if [ $size -le $lowlimit ]
        then
                mailx -s "URGENT: Low disk space for $fs ($size)"
                break
        fi
        if [ $size -le $warninglimit ]
        then
                mailx -s "WARNING: Low disk space for $fs ($size)"
        fi

        df -k $fs|grep $fs|awk '{ print $3; }' >> $wdir/$fs.udisksp.log
        #df -k "/dev/sda5"|grep "/dev/sda5"|awk '{ print $3; }'
        echo ${"/dev/part1"//"/"/"_"}

done


Top
 Profile  
 PostPosted: Mon Mar 08, 2010 4:17 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 549
You mean, changing '/' in $fs to '_'?
Code:
echo "${fs//\//_}"


Top
 Profile  
 PostPosted: Tue Mar 09, 2010 8:42 am   

Joined: Mon Mar 08, 2010 2:26 pm
Posts: 2
works like a charm. why does it need a backslash instead of a forward slash?

do you know of any good links showing other anomalies or escape characters?


edit - it seems mailx requires me to send ctrl-d when entering commands over ssh. what can i do to send this sequence in a shell script?


Top
 Profile  
 PostPosted: Tue Mar 09, 2010 9:44 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 549
Quote:
why does it need a backslash instead of a forward slash?

the backslash protects the slash you want to change to be read as part of the Parameter Expansion (just like in sed's expressions when they contain slash(es))
Quote:
do you know of any good links showing other anomalies or escape characters?

Code:
LANG=C man -P"less -ip 'Parameter Expansion'" bash
?

Quote:
edit - it seems mailx requires me to send ctrl-d when entering commands over ssh. what can i do to send this sequence in a shell script?
I'm not sure, a workaround could be to give a body to your mail...


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP