08-13-2008
Problem with executing script using ssh
I'm writing a script which is meant to ssh into a remote machine, sed a file there, and write the output to a new file on the remote machine. Obviously the easy way to do this is to write and execute the script on the remote machine, but I'm trying to do this all via ssh since I like to keep and execute my scripts from a central location.
So here's my extremely ugly attempt so far:
#Do the following on a remote server:
#ssh in, then operates on some files in the remotedir directory
#sed from an "mg" file (such as host1.mg), replacing all instances of
#host1 and replacing it with a new string from a after.conf
#and then writing the output to the remotedir directory.
#Assume that the after.conf only has one value right now (host2)
remotebox="remote1"
adminssh="sudo -u admin ssh $remotebox"
before="host1"
remotedir="/dir/remotedir"
for after in `cat after.conf`
do
echo $target
$adminssh sed -e 's/$source/$target/g' $remotedir/$source.mg > $target.mg
done
========================================
This works up to a point for me. But as it stands now, it bombs out with the following error:
sed: -e expression #1, char 0: no previous regular expression
I'm assuming this is because I am mis-using sed somehow. Even if I replace the sed command with something like this:
$adminssh "cat $remotedir/$source.mg > $remotedir/$target.mg"
the script bombs out - it seems like the redirect is trying to force the output onto my local machine I think. I'm sure I'm doing several things wrong here. Can anyone help?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
The script startserver.sh has permissions to execute.
Still the nohup command returns error with 'No such file or directory'
Any sugggestions:
$ nohup ./startserver.sh &
Error
$ nohup: appending output to `nohup.out'
nohup: cannot run command `./startserver.sh': No such file or... (4 Replies)
Discussion started by: hemangjani
4 Replies
2. Shell Programming and Scripting
Hello all,
I have a relatively simple script I wrote to generate a count of errors broken down. What I would like to do is execute this script from another server so that I don't actually have to log in to the server to run the check.
The script on what we'll call "Server A" is:
... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
3. Shell Programming and Scripting
Hey fellows,
i've got a probkem while executing a command through a scheduled at-job;
Somehow my script starts looping, when triggered throug at;
It doesnt do so if started manually.
Any ideas?
#!/bin/sh
# atrun uid=33 gid=33
# mail www-data 0
umask 22
cd /var/django/webripper/ripper... (2 Replies)
Discussion started by: viktor4124
2 Replies
4. Shell Programming and Scripting
Hi Friends,
When I try to execute one of my script script1.shl, I am getting the error message as "/tmp/sh1871978.13: cannot create" .
I could not find the specified sh* file in the /tmp directory and I also checked the disk space of /tmp and it is only 60% filled.
Please help me on... (5 Replies)
Discussion started by: mr_manii
5 Replies
5. UNIX for Dummies Questions & Answers
Hi i m writing a script which will fetch data from different machines and display it on single terminal.
I have created a file named SERVERNAMES containing ip address of machines i need to monitor.
Then for every IP i m issuing ssh command to get date on that machine.
However When i m trying... (3 Replies)
Discussion started by: pinga123
3 Replies
6. Shell Programming and Scripting
Hi All,
i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine .
i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies
7. Shell Programming and Scripting
Hi i am getting stuck while executing the script in the below line .Please help me out
if ;then
Name=`grep -i $Size $FILE|awk '{print $(NF-1),$NF}' |head -1`
else
Name="$Nam"
fi (3 Replies)
Discussion started by: soumyamishra
3 Replies
8. Shell Programming and Scripting
Greetings, i've been working with a user-friendly menu on ksh to allow users execute scripts located on a remote server, so they wont have to login and manually launch those scripts every single time.
This is a HP-UX box and currently on a /usr/bin/ksh shell.
I've setup ssh keys on both... (1 Reply)
Discussion started by: nbriozzo
1 Replies
9. Linux
How to execute a script in remote machine through ssh
I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine.
ssh -l username <remote machine> "commands to be exceuted as ; separted"
but how to put the script in the place of... (5 Replies)
Discussion started by: sanvel
5 Replies
10. Shell Programming and Scripting
I have worked on multiple scenarios to execute remote script via ssh.
This problem I am not able to resolve.
2 linux hosts. Server1, Server2
on Server1 I have script called ~/scripts/start_standalone.sh
XXXX
cd $JBOSS_HOME
NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`;... (3 Replies)
Discussion started by: oraclermanpt
3 Replies
LEARN ABOUT SUSE
ssh-copy-id
SSH-COPY-ID(1) General Commands Manual SSH-COPY-ID(1)
NAME
ssh-copy-id - install your public key in a remote machine's authorized_keys
SYNOPSIS
ssh-copy-id [-i [identity_file]] [user@]machine
DESCRIPTION
ssh-copy-id is a script that uses ssh to log into a remote machine (presumably using a login password, so password authentication should be
enabled, unless you've done some clever use of multiple identities)
It also changes the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability (which would oth-
erwise prevent you from logging in, if the remote sshd has StrictModes set in its configuration).
If the -i option is given then the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your
ssh-agent. Otherwise, if this:
ssh-add -L
provides any output, it uses that in preference to the identity file.
If the -i option is used, or the ssh-add produced no output, then it uses the contents of the identity file. Once it has one or more fin-
gerprints (by whatever means) it uses ssh to append them to ~/.ssh/authorized_keys on the remote machine (creating the file, and directory,
if necessary)
SEE ALSO
ssh(1), ssh-agent(1), sshd(8)
OpenSSH 14 November 1999 SSH-COPY-ID(1)