Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

cron tab

Posted on 2006-03-26
18
Medium Priority
?
237 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:mmbaba
  • 7
  • 7
  • 2
  • +2
18 Comments
 
LVL 27

Expert Comment

by:Nopius
ID: 16298202
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/ .

0
 
LVL 6

Expert Comment

by:mightyone
ID: 16299114
or do just

cd /var/lib/mysql/saida_saidacitSaida/;tar cfz /home/saidacitydata.tar.gz *
0
 
LVL 10

Expert Comment

by:Luxana
ID: 16299400
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 :-)


lubo
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 19

Expert Comment

by:alextoft
ID: 16300992
and for the cron jobs, there's the handy cron job generator...

http://www.webmaster-toolkit.com/cron-generator.shtml
0
 

Author Comment

by:mmbaba
ID: 16307348
Nopius, OK, what about crontab ?
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16307518
'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/ .
EOF
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/ .
EOF
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.
0
 

Author Comment

by:mmbaba
ID: 16323739
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 .
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16327686
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.
0
 

Author Comment

by:mmbaba
ID: 16331902
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 ??
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16338079
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.
0
 
LVL 10

Expert Comment

by:Luxana
ID: 16338304
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 ....  

0
 

Author Comment

by:mmbaba
ID: 16339700
This to inform that I did  all my previous opperation under root .
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16339900
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
0
 

Author Comment

by:mmbaba
ID: 16340766
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:

crontabData.php:
===========
<?
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
EOF
crontab /home/root.crontab

and  the old version of "saidacitydata.tar.gz" still appears during monitoring of /home
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16348209
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
0
 

Author Comment

by:mmbaba
ID: 16352983
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)

then
#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 !!





0
 
LVL 27

Accepted Solution

by:
Nopius earned 200 total points
ID: 16353693
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/ .
0
 

Author Comment

by:mmbaba
ID: 16377755
its reallu what I need.,thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question