- 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
11-30-2011 03:21 AM
11-30-2011 03:21 AM
Re: script regarding ssh
Hello..
As per you given script above i have made a test script as below :
root@serverA:/home/rtns>cat testscript
#!/usr/bin/sh
ssh rets@serverB ls "/home/rtns/a/*.abc" | grep -q "MPF*.abc"
if [$? -eq 0]; then
rmdir abc (abc dirctory i have temporarily made in /home/rtns)
fi
Already i am able to do passwordless ssh and able to list the files. But when running this script i am gettin below error :
root@serverA:/home/rtns>./testscript
./testscript[3]: [1: not found.
following test files i have created in serverB in /home/rtns/a :
1_66.abc
2_66.abc
MPF1_1_66.abc
MPF1_2_66.abc
MPF1_3_66.abc
Please mention in the script where i am doing a mistake.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2011 07:02 AM - edited 11-30-2011 07:08 AM
11-30-2011 07:02 AM - edited 11-30-2011 07:08 AM
Re: script regarding ssh
if [$? -eq 0]; then
rmdir abc # (abc directory I have temporarily made in /home/rtns)
fi
>when running this script I am getting below error :
./testscript[3]: [1: not found.
Spacing is important when using [ ] or [[ ]]. You need to cut&paste from the post:
if [ $? -eq 0 ]; then
Note the "1" comes from $? which indicates the grep failed. There is a typo there in the regex, change to:
ssh rets@serverB ls "/home/rtns/a/*.abc" | grep -q "MPF.*\.abc"
Note: grep takes a regex but ls(1) takes a pattern.
>rmdir abc
This isn't likely to work if abc still contains files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2011 11:00 PM
12-01-2011 11:00 PM
Re: script regarding ssh
Hi Dennis,
Thank u very much for ur support.
Your solution worked..
But i m having one more concern:
ssh rtns@serverB ls "/home/rtns/a/*.abc" | grep -q "MPF.*\.abc"
The above command checks all the files of MPF*.abc in serverB. The concern i m having is in serverA the files are generated with .abc extension and with serial nos. For e.g. 1_46446_652110140.abc, 1_46447_652110140.abc and so on. And in serverB they are shipped as MPF1_46446_652110140.abc, MPF1_46447_652110140.abc and so on. I want script that should check that a particular no. of file that has been generated on serverA has been shipped on serverB or not. Say in above case like if 46th file is generated on serverA and if it is shipped in serverB, then it should check the presence of 46th file on serverB and then only it should trigger the other script in serverA. And if the file is not present nothing should happen.
Thanks in advance,
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2011 08:56 AM
12-02-2011 08:56 AM
Re: script regarding ssh
>serverA: 1_46446_652110140.abc, ...
>serverB: MPF1_46446_652110140.abc, ...
>I want script that should check that a particular no. of file that has been generated on serverA has been shipped on serverB or not. Say in above case like if 46th file is generated on serverA and if it is shipped in serverB, then it should check the presence of 46th file on serverB and then only it should trigger the other script in serverA.
Do you want to check to see if there is a match on ALL files that are copied to serverB?
Or do you want to invoke that script if the matching files are on both machines?
And do you want to invoke the script for each match or only once if any matches?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2011 07:02 PM
12-02-2011 07:02 PM
Re: script regarding ssh
>>Do you want to check to see if there is a match on ALL files that are copied to serverB?
Or do you want to invoke that script if the matching files are on both machines?
I will run the script through crontab. I want to invoke the script if the matching files are on both machines. And the script should not run if the file that is present on serverA has not shipped to serverB. That is if file is present on serverA and not present on serverB, then script should not run. That match should be regarding the particular no. of file.
Please revert if any more concern is there.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2011 03:02 PM
12-03-2011 03:02 PM
Re: script regarding ssh
>I want to invoke the script if the matching files are on both machines.
So you don't care if there are extra files on serverA or serverB.
# get basenames of files on each server
ls /serverA-path/*.abc | sed -e 's:.*/::g' > serverA_files
ssh rtns@serverB ls "/home/rtns/a/*.abc" | grep "MPF.*\.abc" | sed -e 's:.*/MPF::g' > serverB_files
# find matches:
comm -12 serverA_files serverB_files > matched_files
if [ -s matched_files ]; then # some matches
run-script-here
fi
rm -f matched_files # cleanup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2011 02:45 AM - edited 12-05-2011 03:25 AM
12-05-2011 02:45 AM - edited 12-05-2011 03:25 AM
Re: script regarding ssh
Hi dennis,
Thank u very much for the script.
I m having some queries about the script that i am mentioning below :
>># get basenames of files on each server
ls /serverA-path/*.abc | sed -e 's:.*/::g' > serverA_files
ssh rtns@serverB ls "/home/rtns/a/*.abc" | grep "MPF.*\.abc" | sed -e 's:.*/MPF::g' > serverB_files
What are the serverA_files and serverB_files. Are they the folders that i have to make in respective directories. In the severB the .abc files are having MPF extension also. Whether that MPF will be removed while matching the files.
>>comm -12 serverA_files serverB_files > matched_files
if [ -s matched_files ]; then # some matches
run-script-here
fi
rm -f matched_files # cleanup
If some files are matched only, then also the script will run or the script will run only after all files are matched. My concern is to invoke the script only after all files on serverA and serverB are matched. If only some files are matched, then script should not run.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2011 09:04 AM - edited 12-05-2011 09:04 AM
12-05-2011 09:04 AM - edited 12-05-2011 09:04 AM
Re: script regarding ssh
>What are the serverA_files and serverB_files. In the serverB the .abc files are having MPF extension also. Whether that MPF will be removed while matching the files.
These are files that contain the list of files on each machine.
The sed command will remove the leading "MPF".
>My concern is to invoke the script only after all files on serverA and serverB are matched. If only some files are matched, then script should not run.
Ok, then:
# find matches:
cmp -s serverA_files serverB_files
if [ $? -eq 0 ]; then # all matched
run-script-here
else
echo "Some files not matched:"
comm -3 serverA_files serverB_files
fi
rm -f serverA_files serverB_files # cleanup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2011 11:27 PM
12-06-2011 11:27 PM
Re: script regarding ssh
Hi dennis,
Thank u very much for the script. I am having a couple of questions for the above script:
>> if [ $? -eq 0 ]; then # all matched
/pathtoscript/backup.sh
whether the script will successfully run by typing the script as above. Or is there any other way to run the script.
>>else
echo "Some files not matched:"
comm -3 serverA_files serverB_files
I will run the script through cron entry per hour. So where the output of the above echo command will be printed.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2011 11:38 PM
12-06-2011 11:38 PM
Re: script regarding ssh
> /pathtoscript/backup.sh
>whether the script will successfully run by typing the script as above. Or is there any other way to run the script?
I don't know how to run your script or what parms it takes??
> echo "Some files not matched:"
> comm -3 serverA_files serverB_files
>I will run the script through cron entry per hour. So where the output of the above echo command will be printed.
It will be mailed to you. I left it there in case you wanted some debugging output.
You could comment it out like:
: echo "Some files not matched:"
: comm -3 serverA_files serverB_files
I used ":" vs "#" since there must be something in the else block.