The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help making a shell script that converts files in a directory wingchun22 Shell Programming and Scripting 15 09-18-2008 12:03 AM
Problem in making shell script girish.batra Shell Programming and Scripting 4 02-08-2008 09:10 AM
making script shary Shell Programming and Scripting 2 06-03-2007 04:16 PM
Need help making a script npereira Shell Programming and Scripting 2 01-06-2007 01:14 PM
Making a SOAP call from within unix shell scripts Laud12345 Shell Programming and Scripting 2 02-16-2005 02:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-15-2008
kaushik02018 kaushik02018 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 27
Smile making shell script

Hi ,
I am new to shell scripting I want to make script as to execute followng command

mysqldump -u (user name) -p(password) database name>filename.sql

this file saves with current date and time

and execute automatically at particular time which I give
  #2 (permalink)  
Old 12-15-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Will it execute the same time every day? Then you should add it to cron. (You'll need to search the forums or FAQ for how to do that.)

To make the script, just edit a file and name it "backupmysql.sh" or something. Then cut-and-paste and edit the fields to suit your needs:
Code:
#!/bin/sh
USER="www"
PASS="xxxx"
DB="zzzz"
DATE=`date +%y-%j`
mysqldump -u $USER -p$PASS $DB >backup-$DATE.sql
  #3 (permalink)  
Old 12-15-2008
kaushik02018 kaushik02018 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 27
Smile

I made shell script but when I execute through shell command it execute successfully but when when i use crontab it execute the backup but shows 0 kb I did following step

step 1 : my shell script is

#! /bin/sh
USER="root"
PASS="nxsmasc"
DB="sme"

DATE=`date +%y-%d-%m`
#date=`date +%F%R` #space between date and +
#longdate=`date +%m%d%y%h%mm%ss`
mysqldump -u $USER -p$PASS $DB>/home/today_sme-$DATE.sql

echo "done"

I stored this file as /usr/bin/bck_sme.sh

step 2: when i execute comand sh bck_sme.sh it excutes successfully

step 3: now through crontab

typed command crontab -e

following entry
29 19 * 12 0-6 /usr/bin/bck_script.sh

but when it execute it shows 0 k file

Please tell where could be problem
  #4 (permalink)  
Old 12-15-2008
ivhb ivhb is offline
Registered User
  
 

Join Date: Dec 2008
Location: CHINA
Posts: 20
check your mail box, read error message. maybe you will find a way
  #5 (permalink)  
Old 12-15-2008
kaushik02018 kaushik02018 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 27
Smile

Quote:
Originally Posted by ivhb View Post
check your mail box, read error message. maybe you will find a way
as i checked mail following found

Subject: Cron <root@ninex> /usr/bin/bck_script.sh
Date: Mon, 15 Dec 2008 20:01:01 0530 (IST)
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

/usr/bin/bck_script.sh: line 12: mysqldump: command not found
done


but this execute by command sh bck_script.sh
not through crontab
  #6 (permalink)  
Old 12-15-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
As always, read the FAQ first!
  #7 (permalink)  
Old 12-15-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
You just have to fix your PATH variable. When you are the command prompt, type:
Code:
echo $PATH
echo $LD_LIBRARY_PATH
You'll need the contents of these either inside your script or inside your crontab.

ALSO, you're outputting to a file in /home. That's normally INCORRECT. Your output file should be something like:
Code:
 ...  >$HOME/today_sme-$DATE.sql
Closed Thread

Bookmarks

Tags
mtime, shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 10:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0