How to install bash script

apps

#1

Hi! I am trying to install a bash script that will email me a backup of my mySQL databases. Can someone please tell me (I’m quite new to this) how to setup this script? Thanks!

#!/bin/bash

This script runs as a nightly cron job to back a MySQL database to a Gmail account

Prints date of the format MM/DD/YY TODAY1="date +%D” # Prints date of the format MMDDYYYY TODAY2=“date +%m%d%Y” # The email address to which we’re sending backups ADDRESS="someone@gmail.com” # Local directory where we’ll be doing work and keeping copies of all archived files BACKUPDIR=”/root/backup” # MySQL username and password MYSQLUSER="root” MYSQLPASS=“f00b@R” # MySQL database to backup (or –all-databases to backup everything) DATABASE=”–all-databases” $ Name of backup file (used for plaintext and gzipped files) FILENAME="mysql_backup”

Change to the backup directory (so absolute directories aren’t included in the archive) cd $BACKUPDIR

Dump the MySQL databases to a plaintext file mysqldump -u $MYSQLUSER -p $MYSQLPASS $DATABASE > $FILENAME_$TODAY2

Package (tar) and compress (gzip) the plaintext MySQL dump # Append the date (MMDDYYYY) to the filename tar czf $FILENAME_$TODAY2.tar.gz $FILENAME_$TODAY2

Mail the resulting archive to our Gmail account # Body of email is the output from the date command at the exact time the cron job runs # Subject is “$FILENAME MM/DD/YY” date | mutt -s “$FILENAME ($TODAY1)” -a $FILENAME_$TODAY2.tar.gz $ADDRESS


#2

I am also having trouble installing a bash script. I dont use much Linux, and I don’t get into the shell much, so please help me out.

I’m trying to setup a script called Hardfeed (that will let me recursively FTP files from another server). http://www.unix.com/showthread.php?s=&threadid=9174

Ive copied the 2 sections into a text editor, saved it as hardfeed, FTP’d it up , and chmod +x hardfeed

then in the shell I try (of course I’ve edited server name, etc.):

$ ./hardfeed -rds xxxl.theservername.com user the.directory
: bad interpreter: No such file or directory

The bad interpreter error has me thinking the first line is the problem:
#! /usr/bin/ksh

So what is the right location? (the thread creator had #! /bin/bash … I tried that to no avail) Or am I on the wrong path to solving this.

Thanks in advance for any help.


#3

If you are using bash (check with ‘echo $SHELL’ from the prompt) as your shell then set the first line to
#!/usr/bin/bash
with no spaces.

What sometimes happens with these scripts when ftp’d is that the format is incorrect.
To correct it use SSH to connect to your shell and open the script in pico with
pico -w script
Go to the very end and add a blank line and save it.

Once you chmod it 755 you can run it as normal with ./script or bash script


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#4

You might want to lay this script out so that it is a bit easier for others to examine.

If it is correct you just need to make sure it is an executable file with
chmod 755 script

Then look at this page in the DreamHost wiki to see how to set up a crontab to run your script.


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#5

[/quote]

#!/usr/bin/bash<<<
that helped. After running echo $SHELL, I found it should be #!/bin/bash

[/quote]

To correct it use SSH to connect to your shell and open the script in pico with
pico -w script<<<
didn’t “work” until I did that. Thanks!

Not that the script worked… but it’s executing… just giving other errors