1833535 Members
2810 Online
110061 Solutions
New Discussion

help with script

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

help with script

Hello guys,

This is just part of my script that I am working on right now. The issue here is when I ran this script, I am not getting what I'm asking for but this is somehow showing me a listing of everything in my directory. Can you please tell me what I could be doing wrong here. Let me know if you need additional info.


Get the start time

ssh $i "tail /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Started' | tail -1" > $TMP_PAGE2

echo "
" >> $TMP_PAGE2
echo $END

# Get the end time - will also use later for COLOR selection

END=$(ssh $i "tail -2 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep -v -e 'Completed' -e 'makrec.log1'")

echo $END

echo "
" >> $TMP_PAGE2
echo "" >> $TMP_PAGE2


5 REPLIES 5
Sridhar Bhaskarla
Honored Contributor
Solution

Re: help with script

Sanman,

I couldn't quite understand this line

END=$(ssh $i "tail -2 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep -v -e 'Completed' -e 'makrec.log1'")



Shouldn't it be

END=`ssh $i "tail.... " `

check the command substituation quotes "`".

-Sri

You may be disappointed if you fail, but you are doomed if you don't try
James R. Ferguson
Acclaimed Contributor

Re: help with script

Hi Sanman:

I believe you want 'grep -i' and *not* 'grep -v' in your construction of the 'END' variable.

BTW, Srhhdar, the syntax is POSIX's which is "preferred" over the tick yntax.

Regards!

...JRF...
linuxfan
Honored Contributor

Re: help with script

Hi,

If you are looking for the completion time, you could do something like,

END=$(ssh $i "tail -2 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep '^Completed'")

Also in your first ssh line where you are redirecting the output to $TMP_PAGE2, you might want to use something like
ssh $i "grep 'Started' /var/opt/ignite/logs/makrec.log1 2> /dev/null | tail -1" > $TMP_PAGE2

(tail by default only shows the last 10 lines)

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Sridhar Bhaskarla
Honored Contributor

Re: help with script

Ooops.. Just overlooked. Please discard my earlier messages.

Yes. You need to replace -v with -i.

The reason why you were getting the output of ls is because, your remsh command with grep -v would assign the string ***** to your variable 'END'.. So when you echo $END = $***** which is equivalent to echo *, you will get the file listing.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Ralph Grothe
Honored Contributor

Re: help with script

Hi Sanman,

just a tiny hint, probably nothing to do with your problem.

When invoking a remote shell (applies to remsh as well as ssh) you need not quote the remote command because everything after the remote hostname is treated as a remote command and its arguments.
But you do have to be careful with any shell meta characters (such as your redirection of stderr).
If such meta characters in the remote command string aren't escaped they will be expanded by your local shell (from where you issue ssh).
This means that if you want to append other commands, or pipe into other commands, or execute a subshell etc on the remote system you have to prepend a '\' to every [|;&<>()].
Madness, thy name is system administration