Visit Our UNIX and Linux User Community


How to escape from the shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to escape from the shell
# 1  
Old 10-07-2009
How to escape from the shell

In a Script I need to push several messages to a function.
My problem here is: I have to print the string v$LOCK on the resulting line which spits out the message. What I want here is not printing the contents of $LOCK I want to escape the shell and printout v$LOCK on the line. But don't know how to.

#!/bin/sh
AWK="/bin/awk"
RESULT="30"
DBPKG="vserver56"

message() {
${AWK} -F## '{system("echo \"" $1 "\" hostname='$DBPKG' severity=" $2 " sub_origin=\""$3"\" script=\"'$SCRIPT'\" \"" $4 "\" SENTRY")}'
}

echo "There is a session locking since $RESULT minutes. See v$LOCK!##CRITICAL##$METAGONIS_APPLICATION##GE_RPM_blocking_waits" | message


Spits out:
There is a session locking since 30 minutes. See v! hostname=vserver56 severity=CRITICAL sub_origin= script= GE_RPM_blocking_waits SENTRY


But should Spit out:
There is a session locking since 30 minutes. See v$LOCK! hostname=vserver56 severity=CRITICAL sub_origin= script= GE_RPM_blocking_waits SENTRY
# 2  
Old 10-07-2009
Just build your entire string within awk and output using print or printf.
# 3  
Old 10-07-2009
just put '\' before the variable

Code:
echo "There is a session locking since $RESULT minutes. See v\$LOCK!##CRITICAL##$METAGONIS_APPLICATION##GE_RPM_blocking_waits" | message

BR
# 4  
Old 10-07-2009
It seemes to work

Quote:
Originally Posted by fpmurphy
Just build your entire string within awk and output using print or printf.
Hello User fpmurphy, I redefined the complete AWK block.
And now it works as you suggested.

Code:
message() {
${AWK} -F## '{system("echo \"" "There is a session locking since '$RESULT' minutes. See v\$LOCK!" "\" hostname='$DBPKG' severity=" $2 " sub_origin=\""$3"\" script=\"'$SCRIPT'\" \"" $4 "\" SENTRY")}'
}

Thanks a lot for your solution.

brgds from

sdohn

Previous Thread | Next Thread
Test Your Knowledge in Computers #514
Difficulty: Easy
As a general rule, the more a variable is used, the longer the variable name should be.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to escape colon sign from variable in shell?

Hello, Below script works fine when I manually enter required information for each file. When it comes to shell in auto mode, it gives various errors. I am under ubuntu 14.04 / trusty. manual_run.sh: #!/bin/bash /usr/bin/ffmpeg -start_at_zero -copyts -i nicki.mp4 -c:v mpeg2video \ -b:v 500k... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters. For example, $ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s It... (1 Reply)
Discussion started by: LMHmedchem
1 Replies

3. Solaris

Escape Sequence for Capital Letters Input at Shell Not Working

Hello, I am running Solaris 8. When issuing the command "stty lcase" all text which is output to the terminal are capitalized. Letters that are supposed to be capitals are preceded by a backslash during output. All text which is input is converted to lower case. This is the expected behaviour... (5 Replies)
Discussion started by: rstor
5 Replies

4. Shell Programming and Scripting

Escape characters

i am executing script from A server which will execute the script in B server , as below. ssh A 'ssh B echo 'select * from testing where name ='test'' i am getting the below output. select * from testing where name=test but i need the output where clause with quotes , tried with... (3 Replies)
Discussion started by: expert
3 Replies

5. Shell Programming and Scripting

Escape ' in awk

I am trying to escape single quote in awk, but could not: awk ' BEGIN{ fstr="COMPRESS('Y','N')" } { substr($1,len-3,4)~/_IND/ len=length($1) if(substr($1,len-3,4)~/_IND/) printf("%-32s%-14s%-5s%-14s\n",$1,$2,$3,$fstr,$4,$5,$6,$7) } ' tt.txt > out.log Error: awk: Field... (8 Replies)
Discussion started by: ysvsr1
8 Replies

6. Shell Programming and Scripting

Escape and combination

Hi I have 2 files like: file1 a 12 b 1 a 3 file2 a 9 c 0 a 8 and i would like to get a 12 a 9 a 3 a 8 i can do it with grep and paste with 3 lines. I tried to combine using: (3 Replies)
Discussion started by: Dedalus
3 Replies

7. UNIX for Dummies Questions & Answers

Need help to escape special characters in Korn shell script

Hi, I would like to display the following message from my shell (Korn) script Copy "old_file.txt" to "new_file.txt" My code looks as follows print "Copy "old_file.txt" to "new_file.txt"" However, when I execute the script, I get the following output Copy old_file.txt to... (6 Replies)
Discussion started by: rogers42
6 Replies

8. Shell Programming and Scripting

Escape character

Hi , I want to change space to ' in my script. I tried doing this, sed 's/ /\'/g' filename but i could not get it. can some one help me please. Thanks, Deepak (4 Replies)
Discussion started by: deepakpv
4 Replies

9. Shell Programming and Scripting

escape characterz...

hey i wanted to know if there is some single unix command to replace all the character escape sequences with their "C" values in a string... The only way i know is repetatively kepp using the grep command for each one. (4 Replies)
Discussion started by: sahithi_khushi
4 Replies

10. Shell Programming and Scripting

Escape sequence

Hi, I have got an application through which an user will submit an address like "c:\tuser\abc". This application calls a script and passes the address to the scripts positional parameter say $1. So $1 should contain "c:\tuser\abc", but when $1 is echoed the "\t" and "\a" are interpreted to... (4 Replies)
Discussion started by: puspendu
4 Replies

Featured Tech Videos