Hello,
I have about 90 servers that I need to update snmp configs. I am trying to write a script that will echo 4 new lines of text into the snmpd.conf file. I have tested it locally and it works when the server ssh into itself but when I try to run the script to ssh into a remote server it logs into the server but does not echo the text into the config file.
I would like to know if its possible to modify a file on a remote server via ssh?
Thanks
What did you try?
There should be no difference between transferring locally and to a remote machine. You may, of course, have to specify a different path.
Yes. I transfer three web sites that way.
Here is my test script
#!/bin/bash
#The SERVERS variable cats a list of servers
SERVERS=`cat servers`;
for i in $SERVERS;
do
ssh root@${i} echo "Server1" >>file
done
This will write to a file on the local machine running the ssh command not the remote host...
After reading this article I corrected my syntax
How To Append File Using SSH
This line:
ssh root@${i} echo "Server1" >>file
Should look like this:
cat file | ssh root@${i} "cat >> file"
#!/bin/bash
#The SERVERS variable cats a list of servers
SERVERS=`cat servers`;
for i in $SERVERS;
do
cat file | ssh root@${i} "cat >> file"
done
I create a local file called "file" that contained the information I need entered in the remote "file" file.
Thanks
Thanks
Try this:
ssh root@${i} 'echo "Server1" >>file'
The single quotes "protect" the command and its redirection so that it is not evaluated by the local shell.
If you are ssh'ing between hosts and NOT changing users (ie: you are root and connecting to the next host as root as well), you need not specify "ssh root@host". Insteady, use "ssh host" (reducing one piece of complexity).