shell scripting problems involving operations with remote machine


 
Thread Tools Search this Thread
Top Forums Programming shell scripting problems involving operations with remote machine
# 1  
Old 12-29-2010
shell scripting problems involving operations with remote machine

Hi,
i have been developing a shell script to transfer a set of files from one ubuntu system to another.

Task: while executing the script the files ( ls, dir, cat) in the source machine should transfer to destination machine(at /home/mac/mac/bin)

While the script is executed once again, It should create a backup file( bacup_date_time) and move all the old files in destination machine(at /home/mac/mac/bin) ti this backup file.

Here is the code i tried with,

Code:
ssh mac@192.168.3.247

filename=bacup_`date +%b_%d_%Y_%H_%M_%S`

mkdir /home/mac/mac/bin/$filename

cp /home/mac/mac/bin/*.bin /home/mac/mac/bin/$filename

scp /bin/ls /bin/dir /bin/cat mac@192.168.3.247:/home/mac/mac/bin

exit

My problem is I am able to run this script, but the backup files are not created.

I can see the files getting transfered, but I am not able to make a new backup directory and also copy the old files in remote machine.


please help me on this.
Thanks in advanceSmilie

---------- Post updated at 12:54 PM ---------- Previous update was at 12:05 PM ----------

Don't mind, I got self help and the problem is solved by adding "here document" concept Smilie

Code:
filename=bacup_`date +%b_%d_%Y_%H_%M_%S`

ssh mac@192.168.3.247 <<EOT

mkdir /home/mac/mac/bin/$filename

cp /home/mac/mac/bin/ls /home/mac/mac/bin/$filename
cp /home/mac/mac/bin/dir /home/mac/mac/bin/$filename
cp /home/mac/mac/bin/cat /home/mac/mac/bin/$filename



EOT
scp /bin/ls /bin/dir /bin/cat mac@192.168.3.247:/home/mac/mac/bin
exit


Last edited by srijith; 12-29-2010 at 02:58 AM..
This User Gave Thanks to srijith For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

2. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

3. OS X (Apple)

Quit a shell script thats running on a remote machine

I'm in a situation where I am executing a shell script(Bash) on another machine remotely using ssh, and for various reasons sometimes need to quit it and restart it. The shell script being run does many different things, so its hard to know what process to kill on the remote machine, and even if I... (2 Replies)
Discussion started by: TheDrizzle
2 Replies

4. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

5. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

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

6. Shell Programming and Scripting

Password change logic for remote machine using shell and expect

Day before yesterday,I got the success creating a shell script using expect tool and now it is running successfully on the server. Now I want to make some changes in paswwordchanger.sh as you can see it can handle only one user i.e dbaguest and not other user.So I am thinking the logic how I can... (0 Replies)
Discussion started by: manish_1678
0 Replies

7. Shell Programming and Scripting

Shell scripting problems - Commands not on local machine

Hello all- I have done a lot of searching tonight, but all leads seem to be dead ends. Forgive me if this has been covered, but I've searched the forum and the internet. I am having trouble building a shell script which uses SSH to login to our schools 1024 cluster grid. The issue that I am... (1 Reply)
Discussion started by: Sagan
1 Replies

8. Shell Programming and Scripting

shell scripting on unix/mysql problems

Hi, I have written a shell script for oracle on unix that does a df for specific files, and then will display the size, Avail, % used and the difference from yesterday to today. I have been asked to place it on some MySql databases that run onn unix and linux also, but when I try to run them I... (2 Replies)
Discussion started by: cat55
2 Replies

9. Shell Programming and Scripting

file operations in shell scripting

hi All, my query... 1.I Have to search for the files in the root directory. 2.i have to search for a pattern in all the files in the root directory and then replace them with a new pattern. 3.Rename the file Explanation: if ABC is the root folder and has 3 subfolders and there are 15... (9 Replies)
Discussion started by: adityamahi
9 Replies

10. Shell Programming and Scripting

Setting environment variable on a remote solaris machine using shell script

Hi, I am trying to set environment variable on a remote machine. I want to do it by running a shell script Here's what I am doin rsh <remote-hostname> -l root "cd /opt/newclient; . ./setp.sh" In setp.sh, I have ############################# cd ../newlib; export... (1 Reply)
Discussion started by: eamani_sun
1 Replies
Login or Register to Ask a Question