LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-05-2010, 09:43 PM   #16
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041

Post your crontab entry and the complete script
 
Old 05-06-2010, 10:29 AM   #17
roqarg
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
This is my script and crontab

SCRIPT:
#!/bin/bash

#Global Variables:
flag=true
weekDayNumber="$(date +'%w')"
localFolder="/opt"
email="/tmp/mailText.txt"
openbravoLogFile="/var/log/bkopenbravo.log"

#PostgreSQL Configuration Variables:
hostName="159.254.230.103"
port="5432"
userName="tad"

#Date/Time Variables:
today="$(date +'%d-%B-%Y')"
now="$(date +'%T')"

#Remote Location Configuration Variables:
remoteHost="cuhv-lvh06.brascuba.cu"
remoteFolder='/mnt/hdmax'
remoteLocation='openbravo/bk'

#Save Folder Name Configuration Variables:
lastWeekDay="$(date --date='7 days ago' +'%A:%d-%B-%Y')"
weekDay="$(date +'%A')"
currentFolder="/tmp/$weekDay:$today"

echo "----------------------------------------------------------------------" >> $openbravoLogFile
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- BK-$weekDay:$today ----------" >> $openbravoLogFile

#----------------------------------------------------------------------------------------------------------
#Create a PostgreSQL DataBase Dump:
/usr/bin/pg_dump -i -h $hostName -p $port -U $userName -F c -b -v -f "/tmp/OBDBdump-$today-$now.db" openbravo
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- Dump Data Base is alredy done." >> $openbravoLogFile

#Create '.tar' File of OpenBravo Source Code Folder:
tar cfj /tmp/Openbravo-$today-$now.tar.bz2 $localFolder/OpenbravoERP/ --exclude "/opt/OpenbravoERP/attachments/*" --exclude "/opt/OpenbravoERP/backup_install/*"
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- Tar File is alredy done." >> $openbravoLogFile

#-------------------------------------------------------------------------------------------------------
mkdir $currentFolder
mv /tmp/OBDBdump-$today-$now.db $currentFolder
mv /tmp/Openbravo-$today-$now.tar.bz2 $currentFolder

#Mount Remote Location:
ssh $remoteHost mount -t ext3 /dev/sdc1 $remoteFolder
sleep 10

scp -rp $currentFolder $remoteHost:$remoteFolder/$remoteLocation
if (( $? )); then echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- Directory copy failed." >> $openbravoLogFile;
echo 'Salva de OpenBravo-Error. Consulte el fichero: /var/log/bkopenbravo.log' > $email;
python /tmp/sendMail.py;
flag=false; else
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- Directory copy is alredy done." >> $openbravoLogFile;

#Remove Old Restore:
ssh $remoteHost bash $remoteFolder/openbravo/clean-old.sh
sleep 10; fi

#-------------------------------------------------------------------------------------------------------
#Remove Temporals Locals Files:

rm -r $currentFolder
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- Temporals directory has been removed." >> $openbravoLogFile

if ($flag = true); then echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- The OpenBravo BK has finished OK ----------">> $openbravoLogFile;
echo 'Salva de OpenBravo-Satisfactoria.' > $email;
python /tmp/sendMail.py; else
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- The OpenBravo BK has not finished ----------">> $openbravoLogFile; fi

CRONTAB:
SHELL=/bin/bash
PATH='/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin'
#PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
05 4 * * * root run-parts /etc/cron.daily
41 18 * * * root /bin/bash /tmp/salvaOpenBravo.sh
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
 
Old 05-06-2010, 10:37 AM   #18
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by catkin View Post
Assuming it's a bash script, try changing the first line to
Code:
#!/bin/bash -l
That's a letter l for login. It will make bash simulate logon so you get your usual environment, similar to at the command line.

sneakyimp's suggestion is good and may give useful information. Try it with 2>&1 at the end of the line, too. That may catch some error messages that > some_file alone does not.
Instead of

Code:
command > some_file 2>&1
use

Code:
command &> some_file
 
1 members found this post helpful.
Old 05-06-2010, 12:06 PM   #19
roqarg
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
IT WORK!!!
IT REALLY WORK!!!
Thank you my brothers!
I agree "2>&1" after the command line and WORKKKK!!!

Thank you again
When you need my help, Don't dude; call me!!!
Thank you again!!!
 
Old 05-06-2010, 12:10 PM   #20
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
If your question is answered, mark the thread as Solved (in Thread Tools).
 
Old 05-06-2010, 12:49 PM   #21
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by MTK358 View Post
Instead of

Code:
command > some_file 2>&1
use

Code:
command &> some_file
That's tidier MTK358 but does it make any functional difference?
 
Old 05-06-2010, 01:34 PM   #22
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by catkin View Post
That's tidier MTK358 but does it make any functional difference?
I doubt it.

It's just that this "2>&1" thing really irritates me because it's placement just doesn't go with the flow of data. Also I don't understand it's syntax.
 
Old 05-06-2010, 01:35 PM   #23
sneakyimp
Member
 
Registered: Dec 2004
Posts: 795

Rep: Reputation: 50
Quote:
Originally Posted by MTK358 View Post
Instead of

Code:
command > some_file 2>&1
use

Code:
command &> some_file
What do these do?? I know you can use ampersand to background some stuff, but haven't seen a > arg1 arg2 before, much less a command > arg1 arg2>arg3
 
Old 05-06-2010, 01:37 PM   #24
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Am I the only one in the universe that knows about bash's &> operator and have to explain it to everyone?

It redirects both stdout and stderr to a file.

Also, "2>&1" never really made sense to me. I just know that "&>" is an elegant replacement that actually makes logical sense.

Last edited by MTK358; 05-06-2010 at 01:39 PM.
 
Old 05-06-2010, 01:53 PM   #25
sneakyimp
Member
 
Registered: Dec 2004
Posts: 795

Rep: Reputation: 50
Oo nice. Thanking...
 
Old 05-06-2010, 02:02 PM   #26
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by sneakyimp View Post
What do these do?? I know you can use ampersand to background some stuff, but haven't seen a > arg1 arg2 before, much less a command > arg1 arg2>arg3
The tokens you represent as arg1-3 are not arguments; arg1 is an redirection target, arg2 is a file descriptor (in this case fd 2 which is stderr) and arg3 means "the same place as fd 1 is going to". Redirections are explained here.
 
Old 05-06-2010, 02:05 PM   #27
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by MTK358 View Post
Am I the only one in the universe that knows about bash's &> operator and have to explain it to everyone?

It redirects both stdout and stderr to a file.

Also, "2>&1" never really made sense to me. I just know that "&>" is an elegant replacement that actually makes logical sense.
I guess many of us have old habits, from before &> was available. Personally I don't find the usage of & in &> any more logical or intuitive than its usage in 2>&1!
 
Old 05-06-2010, 02:15 PM   #28
roqarg
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Hey gays It WORK!!!
Thank you very much
The 2>&1 in the end of the command line written in the script WORKKK!!!
Now thank to you my script work ok!!!
If anyone of you need something don't dude
Call me

I am very grateful!!!

That the force will be with all of you!
 
Old 05-06-2010, 02:18 PM   #29
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by roqarg View Post
Hey gays It WORK!!!
O_o

Not sure if I should report that...

Quote:
Originally Posted by roqarg View Post
If anyone of you need something don't dude
Call me
What is that supposed to mean?

If your question is answered, mark the thread as Solved (in Thread Tools).

Last edited by MTK358; 05-06-2010 at 02:21 PM.
 
Old 05-06-2010, 02:34 PM   #30
roqarg
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Ok "MTK358"
WERE YOU!!!
and I marked the thread a long time ago!!!
 
  


Reply

Tags
do, dont, friend, solution


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script won't run in crontab rastellig Linux - Software 2 03-25-2009 10:18 AM
How to run this script in Crontab baig Linux - Newbie 2 11-30-2008 03:34 PM
how to run crontab in shell script panselva Linux - General 3 05-08-2008 09:33 PM
Crontab -e doesnt run my script ! c0nsur Linux - General 4 08-04-2005 12:21 AM
Script doesn't run in crontab dani81 Linux - General 1 11-16-2004 04:42 AM


All times are GMT -5. The time now is 04:02 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration