LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-19-2005, 03:18 AM   #1
fuelinjection
Member
 
Registered: Nov 2003
Location: County Durham, England
Distribution: Fedora
Posts: 238

Rep: Reputation: 30
Batch files in linux?


Hi All,

I know there isn't a such thing, but is there something similar.

I have a website which runs on a dedicated server, and have several domains. I want to replicate the main website across all of the other domains automatically during the night. To do this, I need some sort of file that has all the commands in it. i.e. copy contents of one folder to another etc etc.

anyone explain how to do this? do I simply just put the commands in a file?
 
Old 05-19-2005, 03:24 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
What you want is shell scripting. Basically, you just put all the commands in the file, but you need to make sure that the first line of the file is

#!/bin/bash

This is a bit of magic that tells the system to execute the file using the BASH shell. (You can use something other than BASH if you want, just put the path to the relevant interpreter).

There's a very good introduction to shell scripting here, and you'll find plenty of info on this site about it as well.

To get the script to run automatically every night, you'll want to use cron. See the manpages for more information.
 
Old 05-19-2005, 03:28 AM   #3
Boby
Member
 
Registered: Feb 2004
Posts: 781

Rep: Reputation: Disabled
In Linux you can write shell scripts (file.sh)

Documentation:
Bash Beginnees Guide
Advanced Bash Scripting Guide

Boby

Edit: Uuups...someone allready replyied

Last edited by Boby; 05-19-2005 at 03:30 AM.
 
Old 05-19-2005, 04:59 AM   #4
fuelinjection
Member
 
Registered: Nov 2003
Location: County Durham, England
Distribution: Fedora
Posts: 238

Original Poster
Rep: Reputation: 30
ok, I created a file and got it to work, but now it wont work anymore. I've copied each line, line by line and pasted them 1 by one and they worked, but when I put them in the script file, it doesnt. All the folders are correct, because I've ran this line by line

heres what I get :

[root@oakley-travel home]# ./replicate.sh
: bad interpreter: No such file or directory

and here is the file

#!/bin/bash
rm -rf /home/httpd/vhosts/internetski.co.uk/httpdocs
cp -R /home/httpd/vhosts/internetholidays.com/httpdocs/ /home/httpd/vhosts/internetski.co.uk
chmod u=rwx /home/httpd/vhosts/internetski.co.uk/httpdocs
chmod g=rx /home/httpd/vhosts/internetski.co.uk/httpdocs
chmod o=w /home/httpd/vhosts/internetski.co.uk/httpdocs
chgrp psaserv /home/httpd/vhosts/internetski.co.uk/httpdocs
chown internetski /home/httpd/vhosts/internetski.co.uk/httpdocs

rm -rf /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
cp -R /home/httpd/vhosts/internetholidays.com/httpdocs/ /home/httpd/vhosts/golf-holiday-deals.com
chmod u=rwx /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
chmod g=rx /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
chmod o=w /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
chgrp psaserv /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
chown golf /home/httpd/vhosts/golf-holiday-deals.com/httpdocs
 
Old 05-19-2005, 05:07 AM   #5
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
You need to give yourself execute permission on the script file. chmod u+x replicate.sh
 
Old 05-19-2005, 05:12 AM   #6
fuelinjection
Member
 
Registered: Nov 2003
Location: County Durham, England
Distribution: Fedora
Posts: 238

Original Poster
Rep: Reputation: 30
still doesnt work...

[root@oakley-travel home]# chmod u+x replicate.sh
[root@oakley-travel home]# ./replicate.sh
: bad interpreter: No such file or directory
[root@oakley-travel home]#


I've copied the script and pasted it into a new file called replicate2.sh, and it worked perfectly fine! Very strange
 
Old 05-19-2005, 05:15 AM   #7
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Hmm

I don't know what's going on there. It may be some other permissions issue, or it could be something else entirely. If you want to try and work out what's going on, I'd guess a good starting point would be comparing the permissions on the two scripts.

Alternatively, you could class this as "Just one of those things" and ignore it
 
Old 05-19-2005, 05:55 AM   #8
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
do you have the bash shell?

Code:
whereis bash
you may need to put
Code:
#!/bin/sh
as your she-bang line
 
Old 05-19-2005, 07:19 AM   #9
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
You probably have a DOS-style newline or some other junk character at end of "#!/bin/bash" line.
 
Old 05-19-2005, 07:46 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
I agree. The "bad interpreter" error often comes from a DOS line-ending, instead of a Unix line-ending.

Yves.
 
Old 05-19-2005, 07:49 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Where is the script located, and how is that partition mounted? Some partitions, especially ones that are world writable should not allow execution of programs and are mounted with the "noexec" option.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux batch files denizen Linux - Newbie 3 07-28-2004 03:56 AM
Batch files spotslayer Linux - Software 3 06-18-2004 07:31 PM
Are there batch files in linux? njbrain Linux - General 3 03-24-2004 04:58 AM
Linux Batch Files sfnitro230 Slackware 13 03-09-2004 02:51 PM
Are linux scripts just as simple as dos batch files? neeyo Linux - General 4 07-21-2002 11:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration