1827671 Members
3438 Online
109967 Solutions
New Discussion

Re: script regarding ssh

 
Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>I tried adding another "then" as below:

 

You don't need another one:  (Nor should you need those "sh" commands.)

if [ $? -eq 0 ]; then
   /home/rtns/x/a.sh

   ssh root@serverB /home/rtns/testdir1/testscript
else
:  echo "Some files not matched:"
:  comm -3 serverA_files serverB_files
fi

rahul_rtns
Frequent Advisor

Re: script regarding ssh

>>ssh root@serverB /home/rtns/testdir1/testscript

The above script is not running on serverB although it is not giving any error.

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>The above script is not running on serverB although it is not giving any error.

 

Add the following (after the #! line):  set -x

 

This will trace the commands in the script.

You could also do it in the original script on serverA to make sure you are getting to that ssh.

rahul_rtns
Frequent Advisor

Re: script regarding ssh

Hi Dennis,

 

The script i am running on serverB through ssh is as below. I used set -x option also in the script.

 

#!/usr/bin/sh
set -x
for i in abc*.xyz
do
if  (test -f  "$i")
then
newname=${i#abc}
/usr/bin/mv $i /home/rtns/testdir2/$newname
fi
done

 

But it is giving the output as:

+ test -f abc*.xyz

 

I run the above script on serverB itself and it is running successfully. But using ssh to run this script giving the above message.

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>The script I am running on serverB through ssh is as below.
>for i in abc*.xyz

 

Are you running this script in the right directory?  Otherwise with ssh, it would default to the home directory.


>if  (test -f  "$i")

 

I wouldn't use test(1).  I would just use:

   if [ -f "$i" ]; then


>But it is giving the output as: + test -f abc*.xyz
>I run the above script on serverB itself and it is running successfully. But using ssh to run this script giving the above message.

 

As I guessed above, it depends on what directory you start in.

rahul_rtns
Frequent Advisor

Re: script regarding ssh

>> Are you running this script in the right directory?  Otherwise with ssh, it would default to the home directory.

 

I am running the script as:

ssh root@serverB /home/rtns/testdir1/testscript

The script is placed in as above path, but still it is not running.

 

>>I wouldn't use test(1).  I would just use:

   if [ -f "$i" ]; then

 

I tried as above also. But still it is giving the same message as :

+ [ -f abc*.xyz ]

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>> Are you running this script in the right directory?  Otherwise with ssh, it would default to the home directory.

 

>I am running the script as:

>ssh root@serverB /home/rtns/testdir1/testscript

 

So the answer to my question is: No

 

You need to invoke it as:

ssh root@serverB "cd XXXX; /home/rtns/testdir1/testscript"

Where XXXX is the directory you want to check.

 

Or you could pass this directory on the command line of your script and with some modifications you can look at the script parms.

 

>But still it is giving the same message as: + [ -f abc*.xyz ]

 

Of course, my suggestion just makes it faster and cleaner, doesn't fix anything.  ;-)

rahul_rtns
Frequent Advisor

Re: script regarding ssh

HI Dennis,

 

>>else
:  echo "Some files not matched:"
:  comm -23 testhoueccp1_files testaustsapdr_files
fi

 

For the above statement if the files are not matced then the files with the above subject line should be mailed to 4 email addresses. How can i put that in the above statement the 4 addresses.

 

Regards,

 

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>How can I put that in the above statement the 4 addresses?


  comm -23 testhoueccp1_files testaustsapdr_files | mailx -s "Some files not matched" alias1 ...

rahul_rtns
Frequent Advisor

Re: script regarding ssh

>>comm -23 testhoueccp1_files testaustsapdr_files | mailx -s "Some files not matched" alias1 ...

 

I tried with the above command. But i am not receiving the mail. It is showing the below message when running the script :

 

Null message body; hope that's ok

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>>comm -23 testhoueccp1_files testaustsapdr_files | mailx -s "Some files not matched" alias1 ...
>I tried with the above command. But I am not receiving the mail: Null message body;

 

This indicates that you have extra files on testaustsapdr_files but not on testhoueccp1_files.

If you want to see both lists use:  comm -3 ...

 

If you don't care, then you'll need to check to see of the output is empty:

comm -23 testhoueccp1_files testaustsapdr_files > testhoueccp1_only

if [ -s testhoueccp1_only ]; then

   mailx -s "Some files not matched" alias1 ... < testhoueccp1_only

fi

rm -f testhoueccp1_only

rahul_rtns
Frequent Advisor

Re: script regarding ssh

>>comm -3 testhoueccp1_files testaustsapdr_files | /usr/bin/mailx -s "Some files not matched:" rahul_rtns@domain.com

 

I am using above to send the mail. When running the script, though it is not giving any message or error, but i am not getting any mail in my mailbox. In my previous post also, i have mentioned this. :)

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

I assumed your script looked like:

cmp -s testhoueccp1_files testaustsapdr_files

if [ $? -eq 0 ]; then
   /home/rtns/x/a.sh

   ssh root@serverB /home/rtns/testdir1/testscript
else

   comm -3 testhoueccp1_files testaustsapdr_files | /usr/bin/mailx -s "Some files not matched:" rahul_rtns@domain.com

fi

rahul_rtns
Frequent Advisor

Re: script regarding ssh

Hi Dennis,

 

My script is like this :

 

#!/usr/bin/sh
ls /home/rtns/testdir/*.abc | sed -e 's:.*/::g' > serverA_files
ssh root@serverB ls "/home/rtns/a/*.abc" | grep "MPF.*\.abc" | sed -e 's:.*/MPF::g' > serverB_files
cmp -s serverA_files serverB_files
if [ $? -eq 0 ]; then
/home/rtns/x/a.sh;
ssh root@serverB "cd /home/rtns/testdir1; /home/rtns/testdir1/testscript"
else
comm -3 serverA_files serverB_files | /usr/bin/mailx -s "Some files not matched:" rahul_rtns@domain.com
fi
rm -f serverA_files serverB_files

 

All the script is ok, except that i am not getting the mail in my mailbox. Though the script is not giving any error or message.

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>I am not getting the mail in my mailbox.

 

Perhaps you don't have your system configured properly to send mail?

What does this do:

echo hello | mailx -s "test mail" rahul_rtns@domain.com

 

Take a look at /var/adm/syslog/mail.log.

 

If your problem is not obvious, search the "Messaging" board.  And then if no solutions, post another topic there.

rahul_rtns
Frequent Advisor

Re: script regarding ssh

I tried
>> echo hello | mailx -s "test mail" rahul_rtns@domain.com

In the mail.log it is giving log as :
Dec 20 00:58:01 houspiqa1 sm-mta[1945]: pBJ9FMjf003896: to=rahul_rtns@domain.com, ctladdr=rtns (116/20), delay=21:42:39, xdelay=00:00:00, mailer=relay, pri=4080152, relay=barbbh1.bwes.net., dsn=4.0.0, stat=Deferred: Connection timed out with barbbh1.bwes.net.
Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>the mail.log it is giving log as:

>stat=Deferred: Connection timed out with barbbh1.bwes.net.

 

Can you do: nslookup barbbh1.bwes.net

 

But before we go to far, you need to create another topic in the correct board.

rahul_rtns
Frequent Advisor

Re: script regarding ssh

Hi Dennis,

 

The problem is not got ressolved. :)

 

Thank you very much for the prompt support. It was really wonderfull to learn a lot of things from you. Hope to communicate with you in near future.

 

Thanks once again..

rahul_rtns
Frequent Advisor

Re: script regarding ssh

Hi Dennis,

 

Just one more point:

 

>>cmp -s serverA_files serverB_files
if [ $? -eq 0 ]; then

In csh the statement if [ $? -eq 0 ]; is not working. May i know how to check the exit status in csh.

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>In csh the statement if [ $? -eq 0 ]; is not working. May I know how to check the exit status in csh.

 

Don't even think of using the scummy C shell.  :-(

mr google says it is something like: if ( $status == 0 ) then

rahul_rtns
Frequent Advisor

Re: script regarding ssh

I used if ($status == 0); then

But it is giving message as :

if: Empty if.

Regards,
Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>I used if ($status == 0); then

 

It looks like I was missing some spaces but that ";" shoudn't be there.

rahul_rtns
Frequent Advisor

Re: script regarding ssh

>>ls /home/rtns/testdir/*.abc | sed -e 's:.*/::g' > serverA_files
     ssh root@serverB ls "/home/rtns/a/*.abc" | grep "MPF.*\.abc" | sed -e 's:.*/MPF::g' > serverB_files
     cmp -s serverA_files serverB_files
    

Can i have the statement for matching only the last file of *.abc pattern in both the servers. Actually there are some more files afer *.abc in both the servers. So it is not working. I want to match only the last file of *.abc pattern. That will work for me..

 

Regards,

Dennis Handly
Acclaimed Contributor

Re: script regarding ssh

>Can I have the statement for matching only the last file of *.abc pattern in both the servers.

 

Just pipe it to tail:

ssh root@serverB ls "/home/rtns/a/*.abc" | grep "MPF.*\.abc" | sed -e 's:.*/MPF::g' | tail -1 > serverB_files

rahul_rtns
Frequent Advisor

Re: script regarding ssh

Hi,

 

I am having a little confusion about the feasiblity of the script that i have to prepart to match the files in two servers and if the files matched then trigger the archiving script in server A. The script that i have prepared is :

 

#!/usr/bin/csh
ls /oracle/MP1/oraarch/*.dbf | sed -e 's:.*/::g' > serverA_files
ssh root@serverB ls "/oracle/MP1/oraarch/*.dbf" | grep "MPFarch.*\.dbf" | sed -e 's:.*/MPFarch::g' > serverB_files
cmp -s serverA_files serverB_files
if ( $status == 0 ) then
/sapbasis/common_scripts/backup_archive.sh
else
comm -3 houeccp1_files austsapdr_files | mailx -s "archiving in prod failed" alias1

endif
rm -f serverA_files serverB_files

 

I am having confusion that when the files in both the servers has matched the backup_archive.sh script will run. But after comparison of the files in both the servers while the backup_archive.sh is running if a new file is generated in serverA, then that file will also get archived by the backup_archive.sh script, so will miss that newly generated file. So is there any way to reduce this risk.

 

Will really appreciate your help on this.

 

Regards,