LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 07-20-2021, 05:04 AM   #1
tuxthegreat
Member
 
Registered: Mar 2018
Distribution: Ubuntu Mate, OSX, Win10, ODROID-N2+
Posts: 176

Rep: Reputation: Disabled
Unhappy Help me figure out this cronjob syntax


I want to make a backup of kodi once a week, let's say Tuesday @ 12:10pm here is what I have so far
Code:
10 12 * * 2 tar -czf kodi-bakup.tar.gz ~/.kodi /home/odroid/kodibackup >/dev/null 2>&1
But it's not doing the cronjob, no output in syslog either just this little output
Code:
Jul 20 11:45:24 odroid crontab[10775]: (root) REPLACE (root)
Jul 20 11:45:24 odroid crontab[10775]: (root) END EDIT (root)
Jul 20 11:46:01 odroid cron[758]: (root) RELOAD (crontabs/root)
Jul 20 11:46:01 odroid CRON[10847]: (root) CMD (tar -czf kodi-bakup.tar.gz ~/.kodi /home/odroid/kodibackup >/dev/null 2>&1)
Jul 20 11:46:52 odroid crontab[10863]: (root) LIST (root)
What am I doing wrong guys ?

Update: It seems that my mistake was using sudo -s and then crontab -e, when I did it without sudo permission it worked. But not completely, I am still unable to save it in /home/odroid/kodibackup , instead it saves it to /home/odroid. Also how can I make it so that when first one is done, the second one will show up as kodi-bakup.tar.gz.1, kodi-bakup.tar.gz.2. and so forth.

Last edited by tuxthegreat; 07-20-2021 at 06:09 AM.
 
Old 07-20-2021, 07:34 AM   #2
petelq
Member
 
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third and fourth
Posts: 627

Rep: Reputation: Disabled
I find that with a slightly more complex instruction, it's better to compile a bash script and run the script in crontab.
 
Old 07-20-2021, 10:14 AM   #3
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
Indeed. The other benefit is with a script you can test it, not wait for cron to run and fine out then. The script can be activated endlessly as you adjust and tinker. Of course the same could be said that you can make the script, then just copy the line into the crontab I suppose once it works. Don't forget about potential PATH issues though. Cron doesn't have the normal PATH by default.

Looking at your entry that may be the issue actually.... PATH isn't set. Try full path to tar.
 
Old 07-20-2021, 10:48 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by AliceWhorton View Post
Thanks for sharing your thoughts!
What did you think was best here? I agree with petelq and jmgibson1981, about putting the complex statements in a script and executing it. What would you have done??
 
Old 07-20-2021, 11:11 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by AliceWhorton View Post
Now i guess that i am going to do as jmgibson1981 said, i just can't find any other solution, maybe you can share some new advice???
Perhaps if you opened your own thread, and provided your own details and asked your own question, we can. You just thanked folks for 'sharing their thoughts'....I asked what, in particular, you found helpful.
 
Old 07-20-2021, 04:07 PM   #6
tuxthegreat
Member
 
Registered: Mar 2018
Distribution: Ubuntu Mate, OSX, Win10, ODROID-N2+
Posts: 176

Original Poster
Rep: Reputation: Disabled
Ok guys calm down, were all friends here OK I like this script idea, it's clean and can be adjusted to my liking, only problem is I don't know how to write a script. But I don't want to give up, I can try to do this with your help. Let's see what I want done, first task is this
Code:
tar -czf kodi-bakup.tar.gz ~/.kodi
then I want to put the resulting tar.gz package into a directory here
Code:
/home/odroid/kodibackup
and third I want this to happen once a week, anytime really, my server runs 24/7. So what can we do guys, let's put on our thinking caps on.

Last edited by tuxthegreat; 07-20-2021 at 04:19 PM.
 
Old 07-20-2021, 04:38 PM   #7
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
You can do it in one shot. I'm not very familiar with tar admittedly. You must have permissions to write to the location.

Code:
tar -czf /home/odroid/kodibackup/kodi-backup.tar.gz ~/.kodi
 
1 members found this post helpful.
Old 07-20-2021, 04:55 PM   #8
tuxthegreat
Member
 
Registered: Mar 2018
Distribution: Ubuntu Mate, OSX, Win10, ODROID-N2+
Posts: 176

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jmgibson1981 View Post
You can do it in one shot. I'm not very familiar with tar admittedly. You must have permissions to write to the location.

Code:
tar -czf /home/odroid/kodibackup/kodi-backup.tar.gz ~/.kodi
Thank you, your method worked, all I had to do was chmod 777 the dir in question and everything works great now. Thank you again.
 
1 members found this post helpful.
Old 07-20-2021, 05:32 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by tuxthegreat View Post
Ok guys calm down, were all friends here OK I like this script idea, it's clean and can be adjusted to my liking, only problem is I don't know how to write a script.
Sure you do...a script, in its most basic form, is just a list of commands you can type in on the command line. Put them in a file, and make the file executable (chmod 755 <filename>).

So your tar command, and whatever else you want can go into "/path/to/your/filename". That's it...the commands in that file will run one by one. If they run on the command line, they'll run in the script. An important note, though, for both scripting and cron jobs...specify the full paths to executables. Don't just put 'tar', put "/usr/bin/tar", and the like.

Granted, scripts can have loops, variables, etc., etc., but in your case, you just want one command.
Quote:
But I don't want to give up, I can try to do this with your help. Let's see what I want done, first task is this
Code:
tar -czf kodi-bakup.tar.gz ~/.kodi
then I want to put the resulting tar.gz package into a directory here
Code:
/home/odroid/kodibackup
and third I want this to happen once a week, anytime really, my server runs 24/7. So what can we do guys, let's put on our thinking caps on.
Have you checked any of the MANY thousands of bash tutorials, since you say you can't write a script?? There's even one in my posting signature...write your script, and put it in cron.

Lots of cron examples and tutorials...have you referenced any?? Simple cron explanation:
Code:
cron field explanation...suitable for inclusion in your crontab file
# *     *     *   *    *        command to be executed
# -     -     -   -    -
# |     |     |   |    |
# |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
# |     |     |   +------- month (1 - 12)
# |     |     +--------- day of        month (1 - 31)
# |     +----------- hour (0 - 23)
# +------------- min (0 - 59)
 
1 members found this post helpful.
Old 07-20-2021, 07:13 PM   #10
tuxthegreat
Member
 
Registered: Mar 2018
Distribution: Ubuntu Mate, OSX, Win10, ODROID-N2+
Posts: 176

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Sure you do...a script, in its most basic form, is just a list of commands you can type in on the command line. Put them in a file, and make the file executable (chmod 755 <filename>).

So your tar command, and whatever else you want can go into "/path/to/your/filename". That's it...the commands in that file will run one by one. If they run on the command line, they'll run in the script. An important note, though, for both scripting and cron jobs...specify the full paths to executables. Don't just put 'tar', put "/usr/bin/tar", and the like.

Granted, scripts can have loops, variables, etc., etc., but in your case, you just want one command.

Have you checked any of the MANY thousands of bash tutorials, since you say you can't write a script?? There's even one in my posting signature...write your script, and put it in cron.

Lots of cron examples and tutorials...have you referenced any?? Simple cron explanation:
Code:
cron field explanation...suitable for inclusion in your crontab file
# *     *     *   *    *        command to be executed
# -     -     -   -    -
# |     |     |   |    |
# |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
# |     |     |   +------- month (1 - 12)
# |     |     +--------- day of        month (1 - 31)
# |     +----------- hour (0 - 23)
# +------------- min (0 - 59)
The link on your bash is causing a "The page isn’t redirecting properly"
 
Old 07-21-2021, 07:28 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by tuxthegreat View Post
The link on your bash is causing a "The page isn’t redirecting properly"
Works for me; many others can be found as well, this is one of the better ones:
https://tldp.org/LDP/Bash-Beginners-Guide/html/
 
1 members found this post helpful.
Old 07-21-2021, 07:28 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by AliceWhorton View Post
Same for me
No, sorry...you just wanted to update your post with your spam essay-writing site. Reported.
 
  


Reply



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
[SOLVED] hwmon keeps changing on reboots and knocks out fancontrol -- can't figure out the wildcard bassmadrigal Slackware 4 07-06-2016 09:23 AM
[SOLVED] Can't figure out syntax error battles Linux - Newbie 3 06-27-2014 08:52 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Some questions i need to figure out, help. levi Linux - Newbie 13 02-10-2003 09:30 PM
help me use IRQ 7!!! I cant figure it out joe_dejesus Linux - General 0 10-03-2001 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:33 AM.

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
Open Source Consulting | Domain Registration