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? |
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. |
In Linux you can write shell scripts (file.sh)
Documentation: Bash Beginnees Guide Advanced Bash Scripting Guide Boby Edit: Uuups...someone allready replyied :p |
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 |
You need to give yourself execute permission on the script file. chmod u+x replicate.sh
|
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 |
Hmm :confused:
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 :) |
do you have the bash shell?
Code:
whereis bash Code:
#!/bin/sh |
You probably have a DOS-style newline or some other junk character at end of "#!/bin/bash" line.
|
I agree. The "bad interpreter" error often comes from a DOS line-ending, instead of a Unix line-ending.
Yves. |
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.
|
All times are GMT -5. The time now is 07:46 AM. |