Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Never written a shell script before...
Closed Thread
Old 08-30-2006, 02:11 PM   #1 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Question Never written a shell script before...

Hey forum,

I have some important files in varying directories on my PC here that I backup every so often on my Linux server. It gets kind of tedious to login to the ftp server, traverse to the directory, transfer the specific files, traverse to another directory, transfer more files, etc...for however many files I need to store (I know, I'm lazy ). I was wondering if/how I can write some kind of shell script that, when ran, will automagically login to the server and transfer all of the specified files to the server, even if they're located in different directories. That way I can backup everything with one command as opposed to a whole bunch.


Does anyone know how to do this and how difficult it is?

Thanks in advance.
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
Old 08-30-2006, 03:34 PM   #2 (permalink)
Greg's Avatar
 
Indeed.

Join Date: Dec 2004

Posts: 1,554

Greg is on a distinguished road

Default

I have no idea about it on Windows, but it probably wouldn't be to hard under Linux if the files that you need backed up are shared.

If you need to do it from Windows, you could look for a tutorial or something
(http://www.google.com/search?hl=en&q...=Google+Search)
__________________
Greg is offline  
Old 08-30-2006, 10:49 PM   #3 (permalink)
 
Super Techie

Join Date: Sep 2005

Posts: 341

hillbillybob

Default

Assuming your Linux box is the server you are wanting to back the files up to, and your on a windows box.

you will create two files. The first .bat file contains the CMD commands that bring up the ftp program native to windows (assuming you aren't using any security such as SSH or SSH2 with key swapping and the such.

The first .bat file may go something like this:
@echo off
ftp -s:ftpcommandfile.bat name.of.server

Before the ftp command you can put some move commands for the files. say, move them to a new directory or what not. After the FTP command you can do some disk cleanup, delete them, move them to an on disk archive directory, whatever. Please note that when execution hits the ftp command above, it will branch off to the second .bat file, the one containing the actual ftp commands you would normall use to log in (username, password - if applicable) and then the put/get commands

The second .bat file may look something like this. Be mindful of the new line (return) charecters

@echo off
username
password

put directory \file
*or*
mput directory \files

put will just put one file, while mput will put multiple files on the server. Very useful. You can use wildcard charecters (*) in any combination
text.* *tex*.txt *ext.* *.*
__________________
The greatest measure of a nation is not it\'s army or economy, but by how many people are trying to get in, and how many people are staying!!
Guns, Guts, and Alcohol made America free.
Born American, Die American
Ubuntu - it\'s all about the bun\'s baby!!!
hillbillybob is offline  
Old 08-30-2006, 11:00 PM   #4 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default

Awesome, not hard at all. Thanks
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
Old 08-31-2006, 01:14 AM   #5 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

Or if you want even simpler, set up samba on your linux box and share the directory you want the files copied to. Then mount the share on your windows box.

The batch file would be as simple as

Code:
@echo off
move windows\path\filename linux\path\filename

__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 08-31-2006, 09:57 AM   #6 (permalink)
 
Super Techie

Join Date: Sep 2005

Posts: 341

hillbillybob

Default

Good point. I didn't think of that.
__________________
The greatest measure of a nation is not it\'s army or economy, but by how many people are trying to get in, and how many people are staying!!
Guns, Guts, and Alcohol made America free.
Born American, Die American
Ubuntu - it\'s all about the bun\'s baby!!!
hillbillybob is offline  
Old 09-01-2006, 02:51 AM   #7 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default

Too bad I didn't try that before I wrote the script


Now I need to write one to backup some stuff from a Linux machine to a Linux machine. Just a couple directories, not much. Is that much different than what I just did in windows? If it depends on the shell, I'm running sh I believe.
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
Old 09-01-2006, 09:11 AM   #8 (permalink)
 
Super Techie

Join Date: Sep 2005

Posts: 341

hillbillybob

Default

Im not familiar with bash scripting, but I know entire books have been written on the subject, so you may have to google that one.

The books were from O'reilly publishing.
__________________
The greatest measure of a nation is not it\'s army or economy, but by how many people are trying to get in, and how many people are staying!!
Guns, Guts, and Alcohol made America free.
Born American, Die American
Ubuntu - it\'s all about the bun\'s baby!!!
hillbillybob is offline  
Old 09-02-2006, 04:01 AM   #9 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default

Turned out to be a piece of cake.

All you do is start out a text file with #!/bin/bash then type a series of Linux shell commands. To run the script, you can do one of several things:

1. Be in the directory that the file is located, then type "bash FILENAME" (no quotes). This one probably differs from shell to shell.

2. Do a chmod +x FILENAME on the script. Then you can either do ./FILENAME , or move the file to the /bin directory and simply type FILENAME, which is what I did.
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On