HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Running embedded script on remote host
Operating System - HP-UX
1834915
Members
2442
Online
110071
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
08-19-2004 11:16 PM
08-19-2004 11:16 PM
Running embedded script on remote host
I can run any script as any user on any host with a simple script as follows: -
# runscript.sh
#
host=$1
user=$2
cat somescript.sh | rexec $host -l root "su - $user -c \"sh\""
i can then run runscript.sh with hostname and user as parameters to run that script anywhere.
i want to fold this into one script (ie remove the need for external somescript.sh). something like: -
# runscript.sh
#
host=$1
user=$2
rexec $host -l root "su - $user -c \"sh\"" < {stuff that somescript.sh used to do}
ls
bdf
bla bla
awk '' etc
EOF
However this only works if I extensively escape all the stuff between <
Is there a way to do this tidily? thinking either of a way to make the shell temporarily not process quoting, substitution etc so the <
# runscript.sh
#
host=$1
user=$2
cat somescript.sh | rexec $host -l root "su - $user -c \"sh\""
i can then run runscript.sh with hostname and user as parameters to run that script anywhere.
i want to fold this into one script (ie remove the need for external somescript.sh). something like: -
# runscript.sh
#
host=$1
user=$2
rexec $host -l root "su - $user -c \"sh\"" <
ls
bdf
bla bla
awk '' etc
EOF
However this only works if I extensively escape all the stuff between <
Is there a way to do this tidily? thinking either of a way to make the shell temporarily not process quoting, substitution etc so the <
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 12:26 AM
08-20-2004 12:26 AM
Re: Running embedded script on remote host
Hai,
We have to give the commands with in "" only. So we have to delimit special chars ",etc to delimit it for action.
Else we have to use remote script file to execute with any problem or, local script file too.
We can some more logic's as,
cat | remsh $host -l $user "cat -|sh"
Else as,
mkdir /usr/hosts
ln -s /usr/bin/remsh /usr/hosts/
/usr/hosts/ "command1;command2;command3"
More it will not show the /etc/copyright messages out there and error messages when you use as like,
rexec $host -l root "su - $user -c \"sh\"" < ls
bdf
EOF
Regards
Muthu
We have to give the commands with in "" only. So we have to delimit special chars ",etc to delimit it for action.
Else we have to use remote script file to execute with any problem or, local script file too.
We can some more logic's as,
cat
Else as,
mkdir /usr/hosts
ln -s /usr/bin/remsh /usr/hosts/
/usr/hosts/
More it will not show the /etc/copyright messages out there and error messages when you use as like,
rexec $host -l root "su - $user -c \"sh\"" <
bdf
EOF
Regards
Muthu
Easy to suggest when don't know about the problem!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 01:38 AM
08-20-2004 01:38 AM
Re: Running embedded script on remote host
hmm, really wanted to avoid escaping everything. hoped there may be some clever way of having an inline "tar" or "uuencode" or something, but guess not.
interesting tip about the $0 use of remsh though!
interesting tip about the $0 use of remsh though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 02:42 AM
08-20-2004 02:42 AM
Re: Running embedded script on remote host
Got a solution (in case anyone ever wants to do similar): -
#!/usr/bin/sh
HOST=$1
USER=$2
F=`grep -n "^#MARKER" $0 | cut -d: -f1`
C=`cat $0 | wc -l`
(( L = C - F ))
tail -$L $0 | rexec $HOST -l root "su - $USER -c \"sh\""
exit 0
#MARKER
rest
of
script
here
Basically it calculates how long the file is after the "#MARKER" comment, then tails itself from here and pipes through the rexec. An exit 0 after the rexec ensures it never runs on local host.
Simple but effective.
#!/usr/bin/sh
HOST=$1
USER=$2
F=`grep -n "^#MARKER" $0 | cut -d: -f1`
C=`cat $0 | wc -l`
(( L = C - F ))
tail -$L $0 | rexec $HOST -l root "su - $USER -c \"sh\""
exit 0
#MARKER
rest
of
script
here
Basically it calculates how long the file is after the "#MARKER" comment, then tails itself from here and pipes through the rexec. An exit 0 after the rexec ensures it never runs on local host.
Simple but effective.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP