making shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting making shell script
# 8  
Old 12-16-2008
Bug

Thanks to you all

I was missing export PATH=$PATH:/usr/bin/
in my shell script thus during contab it could not identify mysqldump command
# 9  
Old 12-17-2008
Bug

I made the script

############################################################
#! /bin/sh
export PATH=$PATH:/opt/mysql/bin/
#echo $PATH
echo $LD_LIBRARY_PATH
USER="root"
PASS="qwa"
DB="shell"
DATE=$(date +%d%b%y_%k.%M.%S)
#DATE=`date +%y-%d-%m`
mysqldump -u $USER -p$PASS $DB | gzip -9>/home/backup/today_sme-$DATE.sql.gz
find /home/smebackup -mtime +60 -exec rm -f {} \;
# script to send simple email
# email subject
SUBJECT="live sme database backup"
# Email To ?
EMAIL="xyz@wqs.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "Backup of shell database is done successfully"> $EMAILMESSAGE
# echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

echo "done"
############################################################

It does
1=takes backup
2=delete file before 60 days
3=send a mail

But when I channged mysqldump-->sqldymp (just for test purpose) still it send mail "backup done successfully" while mysqldump command doesnot execute

I want If command execute successfully then only mail should be sent How can I do this
# 10  
Old 12-31-2008
After the dump, test the exit status of mysqldump.

Quote:
Originally Posted by kaushik02018
I made the script
Code:
# ... <excerpt>
mysqldump -u $USER -p$PASS $DB | gzip -9 >/home/backup/today_sme-$DATE.sql.gz  
if [ $? != 0 ]; then 
  echo Backup FAILED
  exit 1
fi
# ....

# 11  
Old 01-02-2009
When cron runs any job, it does so in a minimal environment, but when you run a job manually, your whole environment is usually setup with .profile (Korn, Bourne and Bash, I believe) or .login/.cshrc (CSH).

In cron, you can add an entry such as...

00 12 * * * . /home/.profile; <command>

so that you get the whole normal profile available to the cronned command.

Jerry
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. Shell Programming and Scripting

Need Help With making this script

Hello, im a new user on this site and learning scripting very slowly at a understanding pace. However i am up with a challenge and require help completing this. The script has to include arguments, variables, decisions and loops. So the script is about calculating the broadcast address for any... (5 Replies)
Discussion started by: tHe666
5 Replies

3. Shell Programming and Scripting

Using shell scripting for making queries on postgres sql

I have a situation where I have a list of airplanes that make a series of flights. Therefore I am looking up the different flights that each airplane makes based on a postgres sql query: select flightid from plane where airplane='DELTAx' As a result I get a series of flight numbers... (0 Replies)
Discussion started by: JSNY
0 Replies

4. Shell Programming and Scripting

I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a... (8 Replies)
Discussion started by: jpontius
8 Replies

5. Shell Programming and Scripting

shell script with decision making

Hi all I need help for the issue below. I need to create script: FORM_cmd=query || import FORM_command=add FORM_msisdn=389881234567 FORM_provcode=SK FORM_attr=12 FORM_cmd can be "query" or "import" when FORM_cmd="query" then execute -> spdci -cmd $FORM_cmd FORM_cmd when... (3 Replies)
Discussion started by: vasil
3 Replies

6. Shell Programming and Scripting

Making file inside shell script

Hi, i have written a shell script and its working fine till now. Now, i have to enhance it with a small updation. i need to make a file inside my file that will contain the below parameters 1) Customer_id 2) Server_id 3) No. Account All the above variables are already been taken in... (3 Replies)
Discussion started by: dazdseg
3 Replies

7. Shell Programming and Scripting

Problem in making shell script

Dear all Dear Brother I am bit new to programming or shell scripting. I have given one shell script which is regarding combining all the 240 or less files in a particular folderwhich is related to one hour of the day. There will be 24 these kind of folders related to a day . It means there... (4 Replies)
Discussion started by: girish.batra
4 Replies

8. Shell Programming and Scripting

making script

hello experts cany any one help me i want to make one script which can rlogin to another machine . but it should not ask me username/password from me of another machine it should take the username and password from the script only. please help me out. regards, shary (2 Replies)
Discussion started by: shary
2 Replies

9. Shell Programming and Scripting

Need help making a script

Here is what I have: #!/bin/bash # Setup year date and month YR=`date +%Y '{print $6}'` MON=`date +%b '{print $2}'` DAY=`date +%d '{print $3}'` file=$YR$MOY$DOM # clear # Dump database using USER/PASS to ..sql mysqldump --user=me -ppass database > database-db.$file.sql The YR, MON and... (2 Replies)
Discussion started by: npereira
2 Replies

10. Shell Programming and Scripting

Making a SOAP call from within unix shell scripts

Hi guys, Is it possible to make SOAP calls from within Unix shell scripts? I need to access a web service from within UNIX in order to lookup something while I am doing some parsing on a file. Regards, Laud (2 Replies)
Discussion started by: Laud12345
2 Replies
Login or Register to Ask a Question