Sponsored Content
Full Discussion: Help echo | sed > file
Top Forums Shell Programming and Scripting Help echo | sed > file Post 302596690 by drbiloukos on Wednesday 8th of February 2012 03:54:37 AM
Old 02-08-2012
Help echo | sed > file

Hello, I am trying to build a very compact script for monitoring FS.
I am stuck in a very simple problem (see code comment).
Please for your help

Code:
SERVER_NAME=`uname -n`
SCRIPT_DIR=/export/home/scripts/fs_mon4
FLAG_DIR=${SCRIPT_DIR}/flags
TEMP_DIR=${SCRIPT_DIR}/tmp
FS[1]="\/$"
FS[2]="\/devices$"
FS[3]="\/system\/contract$"
FS[4]="\/proc$"
FS[5]="\/etc\/mnttab$"
FS[6]="\/etc\/svc\/volatile$"
FS[7]="\/system\/object$"
FS[8]="\/etc\/dfs\/sharetab$"
FS[9]="\/dev\/fd$"
FS[10]="\/var$"
FS[11]="% \/tmp$"
FS[12]="\/var\/run$"
FS[13]="\/dev\/vx\/dmp$"
FS[14]="\/dev\/vx\/rdmp$"
FS[15]="\/app\/oracle$"
FS[16]="\/export\/home$"
FS[17]="\/opt\/SP$"
FS[18]="\/var\/SP$"
FS[19]="\/var\/tmp$"
FS[20]="\/OFA_STGDBPRO$"
FS[21]="\/STDB$"
FS[22]="\/oradata$"
FS[23]="\/archive\/STGDBPRO$"
FS[24]="\/GGATE$"
FS[25]="\/opt\/CA\/UnicenterAutoSysJM$"
FS[26]="\/home\/oracle$"
TH[1]=80
TH[2]=80
TH[3]=80
TH[4]=80
TH[5]=80
TH[6]=80
TH[7]=80
TH[8]=80
TH[9]=80
TH[10]=10
TH[11]=1
TH[12]=80
TH[13]=80
TH[14]=80
TH[15]=80
TH[16]=80
TH[17]=80
TH[18]=80
TH[19]=90
TH[20]=80
TH[21]=80
TH[22]=90
TH[23]=0
TH[24]=0
TH[25]=80
TH[26]=80
df -k | grep -v "Filesystem" |tr -s ' ' | sed 's/%//' | awk '{ print $1, $2, $3, $4, $5, $6 }' > ${TEMP_DIR}/df.tmp
countA=1
while (( countA <= ${#FS[*]} ))
do
PCT=`awk '/'"${FS[countA]}"'/ {print $(NF-1)+0}' ${TEMP_DIR}/df.tmp`
if [[ $PCT -ge ${TH[countA]} ]]; then
#if [[ ! -f ${FLAG_DIR}/$countA.flag ]]
#then
 
echo "To: me@company.com" > msg.txt
echo "Subject: FS WARNING ON $SERVER_NAME" >> msg.txt
echo "Content-Type: text/plain" >> msg.txt
echo "X-Priority: 1 (Highest)" >> msg.txt
echo "X-MSMail-Priority: High" >> msg.txt
##########HELP HERE########################
echo "${FS[countA]} $PCT%" >> msg.txt
###########################################
sendmail -t < msg.txt
echo "${FS[countA]} $PCT% on $SERVER_NAME"
touch ${FLAG_DIR}/$countA.flag
fi
else
rm -f ${FLAG_DIR}/$countA.flag
fi
((countA +=1))
done


Output on email body:
\/archive\/STGDBPRO$ 1%
\/GGATE$ 54%
\/var$ 71%
% \/tmp$ 1%

Desired output (remove \,$,% and whitespace)
/archive\/STGDBPRO 1%
/GGATE 54%
/var 71%
/tmp 1%
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

2. Shell Programming and Scripting

Problem regarding Sed/Echo/Var Init

Greetings, I've visited this forums for a long time and normally got an right answer but this time my problem doesn't seem to go away. What I'm trying to do is the following: VAR="\n\nline1\nline2\nline3\nline4\nline5\nline6\nline7\n\n" (The count of newlines is varying!) If I echo this i... (3 Replies)
Discussion started by: ph1l
3 Replies

3. Shell Programming and Scripting

Help with echo and sed

I am using GNU sed but this does not output "what". Why? HEY=$(echo "hey 70.70.70.70:21 what: " | sed -nr 's/.*(70.70.70.70\|71.71.71.71):(21\|22\|115\|443\|989\|990) (.*):.*/\3/p') echo $HEY (2 Replies)
Discussion started by: limmer
2 Replies

4. UNIX for Dummies Questions & Answers

Having a hard time with the sed/echo commands?

Hello, well what I'm trying to do is to remove underscores from filenames and leaving empty spaces instead: arturas@Universe:/windows/Center/training$ ls big_file failas su shudu arturas@Universe:/windows/Center/training$ a=big_file arturas@Universe:/windows/Center/training$ mv $a `echo... (8 Replies)
Discussion started by: arcelivez
8 Replies

5. Shell Programming and Scripting

echo & sed problems

I need a script to to instert the following line into my postfix master.cf file: flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}if I use echo I get the line truncated: :~ echo flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}... (3 Replies)
Discussion started by: barrydocks
3 Replies

6. Shell Programming and Scripting

Problem with variable ECHO $((SED...

Hi, I'm new here so I want to say hello to everyone first! I searched google and this forum for a similar problem, but wasn't successful #! /bin/bash I'm trying to output (echo) n lines of a text file to the screen (later into another file). But I have problem with the sed command, it won't... (1 Reply)
Discussion started by: studiologe
1 Replies

7. Shell Programming and Scripting

Sending Sed/Echo output to Variable

I have a variable $WORDS that contains a string Then i want to use sed to break it up. echo $WORDS | sed 's// /g' I tried setting this as a variable by doing WORDS2=`echo $WORDS | sed 's// /g'` But when i do this it does not return me to the prompt properly ie. jmpprd-v1> jmpprd-v1>... (4 Replies)
Discussion started by: nitrobass24
4 Replies

8. Shell Programming and Scripting

Replacing part of the sentence using echo and sed

Hi, Iam using ksh and trying to execute the following syntax to replace one word of the sentence with a new word. But somehow sed is not able to replace the old value with new value. Please let me know where Iam going wrong. Sample Code : --> export line="VORTEX,abcdef" export... (3 Replies)
Discussion started by: ajithab
3 Replies

9. UNIX for Dummies Questions & Answers

What is wrong with: echo $PATH | sed s/:/\\n/g

Hello all! I am on Mac (10.8.4) and my shell tcsh (man says version: Astron 6.17.00). Just to precise my tcsh: echo $LC_CTYPE UTF-8 I want to replace all ':' with a new line, to get all paths on one line. I don't find a way to make my shell accept the "\n" My start was: echo... (17 Replies)
Discussion started by: marek
17 Replies

10. Shell Programming and Scripting

Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example File example; nodegroups: check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com I need to take a file with a one line list of hosts separated by commas host.domain.com,host2.domain.com,host3.domain.comand prepend the string " ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 03:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy