cron tab

when I execute the folloing command:

tar cfz /home/data.tar.gz /var/lib/mysql/saidacit_saidacitSaidaCity/*

the following out put appears:

#tar cfz /home/saidacitydata.tar.gz /var/lib/mysql/said_saidaSaida/*

tar: Removing leading `/' from member names

is this affect the zipped files ?

I need to perform a crontab that execute the following commands each day at 8:00 PM

#tar cfz /home/saidacitydata.tar.gz /var/lib/mysql/saida_saidacitSaida/*
#tar cfz /home/saidacityweb.tar.gz /home/saida/public_html/*

in both saida user and root user
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Artysystem administratorCommented:
It's better to use relative filenames in tar archives (so whey will not unpack to /)

Try this usage:
tar cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saida_saidacitSaida/ .

and this:
tar cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saida_saidacitSaida/ .
tar cfz /home/saidacityweb.tar.gz -C /home/saida/public_html/ .

or do just

cd /var/lib/mysql/saida_saidacitSaida/;tar cfz /home/saidacitydata.tar.gz *
Hi mmbaba,

Do not worry about the message "ar: Removing leading `/' from member names" this is mostly done from security reasons. Imagine that you create tar of your whole /etc directory. In the case that  the leading "/" is not removed and you copy your etc.tar.gz file to other system and you uncompress it you will overwrite whole /etc directory which can leade to disaster. Once the '/' is removed you will unpack it into current directory.

Hope this helps :-)

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

and for the cron jobs, there's the handy cron job generator...
mmbabaAuthor Commented:
Nopius, OK, what about crontab ?
Artysystem administratorCommented:
'I need to perform a crontab that execute the following commands each day at 8:00 PM'
man crontab:
A crontab file consists of lines of  six  fields  each.
The first five are
     integer patterns that specify the following:

     minute (0-59),
     hour (0-23),
     day of the month (1-31),
     month of the year (1-12),
     day of the week (0-6 with 0=Sunday).

for root run this:
su - root
password: ****
cat <<EOF > /tmp/root.crontab
0 20 * * * /usr/bin/tar cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saida_saidacitSaida/ .
crontab /tmp/root.crontab

for user saida (under root):
su - saida
cat <<EOF > /tmp/saida.crontab
0 20 * * * /usr/bin/tar cfz /home/saidacityweb.tar.gz -C /home/saida/public_html/ .
crontab /tmp/saida.crontab

P.S. user saida should have write access to /home (which is not normally true) or change /home/saidacityweb.tar.gz to some other place where user saida have write permissions.
mmbabaAuthor Commented:
Great  Nopius,

I have seen that you put the command in a tmp file, what if I want to put the the commands in permanent file ? so I can  later open them then edit what I need .
Artysystem administratorCommented:
Personnaly I prefer to keep all crontabs for all users in "crontab" subfolder of user's home directory.
So, the user may edit it by hand and install it when he want.
/tmp was used just as sample. Yes you may edit it there and install again.
On most systems /tmp is cleaned on reboot, so it's better to move crontabs to permanent location.
mmbabaAuthor Commented:
I did what you said,

# crontab -e give :

0 20 * * * /usr/bin/tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .

more than 24 h have been passed and the file did not created under /home ?

what coud be the problem ??
Artysystem administratorCommented:
The problem, as I said in my previous comment may be in write permisssions:

'P.S. user saida should have write access to /home (which is not normally true) or change /home/saidacityweb.tar.gz to some other place where user saida have write permissions.'

Probably user saida have no write permissions to /home (you may check it, run from user saida 'touch /home/saidacitydata.tar.gz')
If you are running from user saida, place your archive in some other place (where user saida have write permissions) or else run this command from root crontab.
HI mmbaba,

>more than 24 h have been passed and the file did not created under /home ?

Why don't you make something simple for testing pusposes. Once you know that cron runs the given script you can implement heavy stuff. For example make it that after one minute cron will touch a file in your /tmp directory. Once you sure that this is working try the same with your home directory. If this is working try tar and so on ....  

mmbabaAuthor Commented:
This to inform that I did  all my previous opperation under root .
Artysystem administratorCommented:
Add second line to crontab, as Luxana said:
0 20 * * * /usr/bin/tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .
* * * * * /usr/bin/touch /home/saidacitydata.tar.gz

and then enable this crontab.
P.S. It's prererable not to use crontab -e, because some key combinations (Ctrl-D or Ctrl-C) may completely remove your crontab
mmbabaAuthor Commented:
I think that  just changing the time using the second command not right,

I tried to solve my problem by another way, I wrote the following php  script under /home:

echo exec('tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .');

then I tried to execute it each 1 minute using :

cat <<EOF > /home/root.crontab
* * * * * * /usr/local/bin/php /home/crontabData.php
crontab /home/root.crontab

and  the old version of "saidacitydata.tar.gz" still appears during monitoring of /home
Artysystem administratorCommented:
What are you waiting to get after execution of:
echo exec('tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .');

1) Cron daemon has no controlling terminal, so nowhere to 'echo'
2) Please specify full path to 'tar' command in any case (either in crontab or in php)
you may get full path by 'which tar' command

Also please be shure that cron daemon is running: ps -ax | grep cron
And that your users have permissions to run cron jobs:
either both files /etc/cron.allow and /etc/cron.deny are empty
or (if not empty) user is absent in cron.deny file
mmbabaAuthor Commented:
1 - /etc/cron.allow and /etc/cron.deny are empty
2 - which tar  ---> /bin/tar

so I put in crontabData.php the following
exec('/bin/tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .');

and I tried :

#/usr/local/bin/php crontabData.php

and the file has been created as expected.

so in my file "/home/root.crontab"
* * * * * * /usr/local/bin/php /home/crontabData.php  (execution each minute)

#crontab /home/root.crontab

the following process list of:
#ps aux | grep cron

root     26111  0.0  0.0  1404  596 ?        S    Feb11   0:37 crond

but the file through this comand note updated each minute !!

Artysystem administratorCommented:
Now you can execute tar directly, without php (the problem was in path to tar):

0 20 * * * /bin/tar  cfz /home/saidacitydata.tar.gz -C /var/lib/mysql/saidacit_saidacitSaidaCity/ .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmbabaAuthor Commented:
its reallu what I need.,thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.