- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- executing a script in remote servers
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
Forums
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
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
09-29-2009 09:25 AM
09-29-2009 09:25 AM
executing a script in remote servers
i am working on a script tat will provide all the LVM data of a HP UX server, it's called LVM_Inventory.sh, and now i am working on a script that will execute LVM_Inventory.sh in remote servers,
so first i have to check if the script existe and then execute it, afteer i will add how to download the result file, if it does not exist the script will copy LVM_Inventory.sh in the remote server an then run it
i tried to fix the script all the day and i just don't know how to do it, so here is my script and i will be happy of your feedbacks
#! /bin/ksh
############################################
### this script needs a list of servers names
### each line is a server name
############################################
liste=$1
DIR_SCRIPT_LVM_INVENTORY="/home/edsadm/scripts/"
NAME_SCRIPT_LVM_INVENTORY="LVM_Inventory.sh"
SCRIPT_LVM_INVENTORY="$DIR_SCRIPT_LVM_INVENTORY$NAME_SCRIPT_LVM_INVENTORY"
for nomServeur in $(cat "$liste")
do
#RET=`remsh $nomServeur -l root 'test -f $SCRIPT_LVM_INVENTORY ; echo $?'`
if [ $RET -eq 0 ]
then
echo "then $nomServeur"
remsh $nomServeur $SCRIPT_LVM_INVENTORY $nomServeur
else
echo "else $nomServeur"
# on copie le fichier sur le serveur
host=`hostname`
remsh "$nomServeur" -l root "mkdir -p /home/edsadm/scripts 2>/dev/null"
rcp -p "root@$host:$SCRIPT_LVM_INVENTORY" "root@$nomServeur:$SCRIPT_LVM_INVENTORY"
remsh $nomServeur $SCRIPT_LVM_INVENTORY $nomServeur
fi
done
the test of existance of the file does not give the true value, it gives the non existence of the file even if i just copy it my self.
- Tags:
- remsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2009 10:07 AM
09-29-2009 10:07 AM
Re: executing a script in remote servers
'test -f $SCRIPT_LVM_INVENTORY ; echo $?'
mean that it's looking for a file named:
$SCRIPT_LVM_INVENTORY
not:
/home/edsadm/scripts/LVM_Inventory.sh
.
Try quotation marks:
"test -f $SCRIPT_LVM_INVENTORY ; echo $?"
You know, like the other remsh command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2009 10:10 AM
09-29-2009 10:10 AM
Re: executing a script in remote servers
First, I assume that you didn't mean to comment out the establishment of the 'RET' variable with:
#RET=`remsh $nomServeur -l root 'test -f $SCRIPT_LVM_INVENTORY ; echo $?'`
Then, instead of :
RET=`remsh $nomServeur -l root 'test -f $SCRIPT_LVM_INVENTORY ; echo $?'`
I would do:
RET=$(ssh $nonServeur -n -l root [ -f ${FILE} ] && echo 0)
Notice that I didn't quote the command argument allowing the shell to interpret the metacharacters on the _local_ host first.
Lastly, notice that I have used 'ssh' instead of the less-secure 'remsh'. The syntax is virtually identical and I find it more reliable.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2009 01:56 PM
09-29-2009 01:56 PM
Re: executing a script in remote servers
If you are going to use $(), you should also remove cat. And probably no need to use "" around $liste, unless you have spaces:
for nomServeur in $(< $liste); do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2009 02:41 AM
09-30-2009 02:41 AM
Re: executing a script in remote servers
let me thank all of you for your answers.
Steven, i try you proposition but it doesn't work with double quotes "" also,
James R. i can't use ssh so i used remsh without -n (as you said that's the same), but it did not work.
Dennis thank you for you help also.
so before making the boucle and so on, i write another script to find the solution of the probleme and then i will write it in my first script, here is the new script with the results.
i test in two servers, frls does not have the script on it so i must have 1 in the return of the test, and frlg which has the script and must have 0 in the return of the test.
#! /bin/ksh
DIR_SCRIPT_LVM_INVENTORY="/home/edsadm/scripts/"
NAME_SCRIPT_LVM_INVENTORY="LVM_Inventory.sh"
SCRIPT_LVM_INVENTORY="$DIR_SCRIPT_LVM_INVENTORY$NAME_SCRIPT_LVM_INVENTORY"
r=$(remsh frls -l root 'test -f /home/edsadm/scripts/LVM_Inventory.sh ; echo $?')
s=$(remsh frlg -l root 'test -f /home/edsadm/scripts/LVM_Inventory.sh ; echo $?')
RET=1
RET=$(remsh frls -l root [ -f ${SCRIPT_LVM_INVENTORY} ] && echo 0)
ET=$(remsh frlg -l root [ -f ${SCRIPT_LVM_INVENTORY} ] && echo 0)
rp=$(remsh frls -l root "test -f $SCRIPT_LVM_INVENTORY ; echo $?")
sp=$(remsh frlg -l root "test -f $SCRIPT_LVM_INVENTORY ; echo $?")
echo "Forum example"
echo "$RET $ET"
echo "correct"
echo "$r $s"
echo "with parameter"
echo "$rp $sp"
and here is the result
frd7:/root/home/root (root) ./LVM_Payasage_Inventory.sh
Forum example
0 0
correct
1 0
with parameter
0 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2009 05:52 AM
09-30-2009 05:52 AM
Re: executing a script in remote servers
> James R. i can't use ssh so i used remsh without -n (as you said that's the same), but it did not work.
The '-n' works for 'ssh' or 'remsh'. It is generally wise to include it: see the manpages for an explanation.
For the snippet of code I suggested, 'remsh' does not consistently work while 'ssh' does.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2009 07:52 AM
09-30-2009 07:52 AM
Re: executing a script in remote servers
> doesn't work with double quotes "" also,
Some of it does. You want
$file_name
inside quotation marks, because you want
_this_ variable evaluated on the _local_
host, where the variable is defined, but you
need to have
$?
inside apostrophes, because you don't want
_it_ evaluated here, you want _it_ evaluated
on the _remote_ host, where it gets the
status value from the remote "test" command.
For example:
dy # echo $file_yes
/root/.profile
dy # echo $file_no
/root/.profileXX
dy # remsh dy -l root "test -f $file_yes ; "'echo $?'
0
dy # remsh dy -l root "test -f $file_no ; "'echo $?'
1
And if your file name includes problem
characters, then you need to work a little
harder:
dy # echo $file_odd
a b c
dy # ls -l 'a b c'
-rw-r--r-- 1 root sys 5 Sep 30 10:42 a b c
dy # remsh dy -l root 'test -f "'"$file_yes"'" ; echo $?'
0
dy # remsh dy -l root 'test -f "'"$file_no"'" ; echo $?'
1
dy # remsh dy -l root 'test -f "'"$file_odd"'" ; echo $?'
0
You need to think about which shell where
sees which quotation marks.
Everything's complicated.