- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script regarding ssh
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2011 05:27 AM
12-07-2011 05:27 AM
Re: script regarding ssh
Hi dennis,
Thnx for the script. I have tested a test script based on above script and it is working successfully. Just one more concern i m having. I am providing the test script which i have tested:
#!/usr/bin/sh
ls /home/rtns/testdir/*.abc | sed -e 's:.*/::g' > serverA_files
ssh root@austsapdr 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
sh /home/rtns/x/a.sh
else
: echo "Some files not matched:"
: comm -3 serverA_files serverB_files
fi
rm -f serverA_files serverB_files
>>if [ $? -eq 0 ]; then
sh /home/rtns/x/a.sh
If the exit status is not 0 then the script will not run. But if the exit status is zero and the script when runs, then after that an ssh should be done to serverB to run a script on serverB. Or any other way to do this??
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2011 01:09 PM
12-07-2011 01:09 PM
Re: script regarding ssh
>Thnx for the script. I have tested a test script based on above script and it is working successfully.
(If you are happy, please click on the Kudos! star of the posts that helped.)
>sh /home/rtns/x/a.sh
There is no need to use "sh" on this line. Just make sure your script is executable and has "#!..." on the first line.
>>if [ $? -eq 0 ]; then
sh /home/rtns/x/a.sh
>if the exit status is zero and the script runs, then after that an ssh should be done to serverB to run a script on serverB. Or any other way to do this?
You can either put that ssh into a.sh (but it would have to know about serverB) or add that ssh right after.
Do you also need to check the exit status of a.sh?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2011 10:16 PM
12-07-2011 10:16 PM
Re: script regarding ssh
>>if [ $? -eq 0 ]; then
sh /home/rtns/x/a.sh
>>Do you also need to check the exit status of a.sh?
No. I dont need the exit status of a.sh. I am concern of only that if a.sh runs (i.e. status of [ $? -eq 0 ] is zero) then only ssh is to do done to serverB to run a script there and if a.sh do not runs (i.e. status of [ $? -eq 0 ] is non-zero), then ssh should not be done to serverB.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2011 12:27 AM
12-08-2011 12:27 AM
Re: script regarding ssh
>I am concern of only that if a.sh runs then only ssh is to do done to serverB to run a script there ...
That "if" will do that. You just need to add that ssh in the "then" block after a.sh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2011 02:38 AM
12-08-2011 02:38 AM
Re: script regarding ssh
I tried adding another "then" as below :
#!/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
sh /home/rtns/x/a.sh; then
ssh root@serverB sh /home/rtns/testdir1/testscript
else
: echo "Some files not matched:"
: comm -3 serverA_files serverB_files
fi
rm -f serverA_files serverB_files
But it given the following error :
root@serverA:/home/rtns>./testscript2 (testscript2 is the above script)
Password:
Password:
./testscript2[5]: Syntax error at line 7 : `then' is not expected.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2011 02:52 AM
12-08-2011 02:52 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2011 05:01 AM
12-08-2011 05:01 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2011 12:54 PM
12-08-2011 12:54 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2011 03:19 AM
12-12-2011 03:19 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2011 12:35 PM
12-12-2011 12:35 PM
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.