1834051 Members
2481 Online
110063 Solutions
New Discussion

script assistance

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

script assistance

Any help is greatly appreciated and points will be assigned.

Write a script to securely transfer a file named "test1.log" from the server named "server2" to the server name "server1". Use the account name of sysadmin and note any additional requirements to make the script work in an unattended mode.
3 REPLIES 3
Ivan Ferreira
Honored Contributor
Solution

Re: script assistance

To do that, you only need scp with public key authentication.

Create a public key pair without passphrase on server1:

ssh-keygen -t dsa

Copy the $HOME/.ssh/id_dsa.pub to server2 in $HOME/.ssh/authorized_keys

On both servers run

cd $HOME
chmod -R go-w .ssh

Use scp to transfer the files from server1:

scp test1.log server2:/destination/directory

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Steven E. Protter
Exalted Contributor

Re: script assistance

scp can do this as noted above.

to pull this off the user MUST own home diretory with 755 permissions and .ssh must have tight 655 permissions as well. Plenty of docs on this on itrc some of which I wrote.

If port 514 is open between the machines, syslog can do it also.

You add an entry for a second syslog or maillog

@hostnameof server

Like magic the log entries for one server appear on another.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Alexander Chuzhoy
Honored Contributor

Re: script assistance

After you exchange keys this script will only have one line.

scp server2:/path/filename sysadmin@server1:/path/


save this line in to a file make this file executable with chmod +x filename.

to exchange keys:
ssh-keygen -d
then
scp $HOME:/.ssh/id_dsa.pub sysadmin@server1:/home/sysadmin/
then login to server2 as sysadmin.
then,while you're on server2 do:
cat /home/sysadmin/id_dsa.pub >> /home/sysadmin/.ssh/authorized_keys
At this poing you can logout and your one line script will work without prompts.

In assumed here that the username is sysadmin -in case you use a different user simply replace sysadmin with the correct username