Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

cronjob tar compress

cronjobz

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 robzuclm

robzuclm

    CC Newcomer

  • Member
  • PipPip
  • 19 posts

Posted 21 May 2014 - 11:50 PM

im having problem with this inserting in cron jobs it won't execute

 

* * * * * sudo tar -zcvf  nameofthetarname.tar.gz  foldertobecompressintar -source /*

im trying to do it like this but won't work in cron

 

now=$(date +"%Y%m%d%H%s")
tar -zcvf this$now.tar.gz  html/*

 



#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 22 May 2014 - 12:26 AM

You wouldn't need sudo, and you need to give tar (when in cron) the absolute paths of input and output.

 

Better yet, don't place the commands in the crontab, make a script of your own (don't forget to change directory to the one you intend to work on, and to use the absolute paths)



#3 robzuclm

robzuclm

    CC Newcomer

  • Member
  • PipPip
  • 19 posts

Posted 22 May 2014 - 12:41 AM

can you give some sample what u mean?



#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 27 May 2014 - 11:42 AM

I'm pretty sure cron doesn't allow inline code like bash does. What BlackRabbit is saying is to create a script with this:

#!/bin/bash

now=$(date +"%Y%m%d%H%s")
tar -zcvf this$now.tar.gz $1 -source $2

and then in your cron job run that script like this:

* * * * * path/to/myscript.sh foldertobecompressintar /*


sudo rm -rf / && echo $'Sanitize your inputs!'


#5 Ableson

Ableson

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 08 June 2014 - 09:06 AM

Look like this tools at https://www.easycron...et-up-cron-jobs, maybe help you set up cron job.