New answers tagged

0

What you need is an SMTP server, a Mail Transfer Agent. You can simply install opensmtpd and start the service. The default configuration is to do local delivery of mail.


1

After some extended discussion it appears that the filesystem may corrupted. As an example, rm -rf fails - as root - on a normal tree of files. After unmounting the filesystem, fsck identified it as NTFS. Frustratingly I have seen NTFS fail on other Linux-based platforms under the heavy loads incurred from rsnapshot. There's nothing sufficiently repeatable ...


4

This original advice applies only to Debian-based distributions: The two crontab segments you've shown are not the same crontab. So your jobs are running twice (once from /etc/cron.d/rsnapshot and once from crontab -l). Remove one set, for example with sudo crontab -r, and it'll start working properly. The next suggestion is to ensure that sync_first is ...


-1

Usually, when your cron tasks are run by root you need to set $HOME variable in your crontab or shell script. HOME=/absolute/path/to/your/application Then just run your script with relative path: * * * * * script.sh


1

mailx only sends mail if you pass it the destination address on the command line. When you run it with no arguments, it reads interactive commands from its standard input. Beware that your tests fed it garbage which has been interpreted as commands; some of these commands may have corrupted your mailboxes, sent out emails, etc. Tell mailx to run mailx -t, ...


0

Thanks to @Andrew for pointing to ssh-agent. As far as I can see, if one wants to be able to establish the tunnel without having to enter a password each time, the password must be stored or removed. I chose to remove it. For the record, here are some clean-ups based on the comments I got: #!/usr/bin/env bash # Establish tunnel createTunnel() { /usr/...


0

Log rotation should probably be initiated more than once a day, probably every hour. The decision to actually rotate the logs or not should be left to the log rotation facility (logrotate in your case), not to cron. By invoking logrotate once every 24 hours, the following scenario will likely happen: cron initiates the log rotation job at X (a time). ...


0

Now it is working fine , i had to put the absolute path of the file wishing to be created from the script .


1

The cron daemon takes crontabs from several files. Dir /etc/cron.d and file /etc/crontab are special, they can be manually edited and the daemon will always see the new version automatically. Also these are the only crontab files which have also username field. The crontabs of individual users (usually in /var/spool/cron/crontabs) are not re-read ...


1

Is the line you showed extracted from the output of crontab -l or did it come from a file named crontab? The running crontabs are usually found in a directory under /var/spool. This location can vary. The actual crontabs are usually named according the the userid they apply to. It is common to extract the crontab to a file in order to edit it. However,...


0

It is working after replacing * * * * * /home/anmol/display-notif.sh with * * * * * sudo -u anmol /home/anmol/display-notif.sh


0

Quoting from here: The other answer is great! But it requires root cron. If you want to hibernate from non-sudo cron, there are 2 options: 1. Using polkit Make a file containing the following: [Enable hibernate to be run via cron] Identity=unix-user:* Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.hibernate-...


0

Keep your cron on a single server (server1 ?) and then run the scripts remotely from the same controlling machine by setting up an ssh key: ssh server2 /path/to/script This way your jobs are all scheduled in one place, and you aren't recreating crons everywhere.


0

If you just want to check to see if the script is currently running, and if not, run it every hour, you could just do something like: pgrep -x script-name.sh || script-name.sh But you wouldn't want to do this unless you used a unique name for your script--don't use it with "echo" as your example above.


1

Usually, cron sends the output of the jobs it runs to the relevant user; so -v is useful there because you get an email with the full output of the rsync command. On a correctly-configured system, even mail to root goes to the appropriate user. For this to work you need mail to be setup appropriately on the system running cron; that used to be common on ...


0

export DISPLAY=:0.0 xhost localuser /usr/bin/firefox Just from looking at the above cron command I can see why it won’t work. The usage for the export command is export name[=word]... In most (if not all) POSIX shells, the rest of the words following export DISPLAY=:0.0 will be ignored. Also, the xhost command is used incorrectly. Run xhost by itself ...


-2

With crontab, you can only do an action like (copy a file, reboot computer, enable network, on or off a service, so on) that runs in background, thease actions are not related to GUI and ubuntu-desktop tools. for example you cannot use bellow actions in crontab : open a GUI open a program take screenshot, so on... you can use of startup-application ...


1

Turns out there was an alias defined for root in /etc/mail/aliases and this is where it was coming from. There's no way for me to bypass it per-command with this on, as any mail sent to root's mailbox will automatically get forwarded to that alias.


2

Each user has its own crontab. By allowing the non-root users to write a root's crontab you make a security breach in your system, this is why crond rejects a file with such permissions. If you need to allow non-root accounts to perform some actions that require root privileges then consider to use sudo


2

Here is a more robust form that correctly handles spaces (or even newlines) in filenames and directory names. find . -type f -name '*.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].qz' -exec sh -c 'fdate="${1%.qz}"; fdate="${fdate##*.}"; [ "$fdate" "<" "$(date +%F -d "7 days ago")" ] && rm "$1"' find-sh {} \; This involves a lot of shell trickery ...


1

I can't post a comment, but here is the command to create empty test files: for i in {0..50};do touch blah.`date "+%Y-%m-%d" -d "$i days ago"`.qz ;done I believe Dave's answer does the trick. (I needed to complete the for command with '; do') A great one liner for cron.


0

I'll recommend a short script, basically gets all the filenames that have a date like format, then loops through them, checking if seven days ago is later than the date found in the filename, and if so, deletes it. The date parsing basically makes an integer in the format YYYYMMDD and compares using that, which should work fine since the larger units have ...


0

You can use this: find /my/directory -type f -name "*file-name.$(date -d '7 days ago' +%Y-%m-%d).qz" -delete This lets the shell tell us what date was 7 days a go: $(date -d '7 days ago' +%Y-%m-%d) For example: if today is 2016-06-06 this will be: 2016-05-30 So, whenever your command is executed, that will take the date 7 days ago and so on. I hope ...


3

Your perl script has open CSV2, "<csv2" or die; ... open CSV1, "<csv1" or die; Where are those files located? cron's current directory is the home directory of the user. If the files are in the "newitems" directory, you have to cd there first. Make sure you're not making any other assumptions about the environment in your programs. I find this is ...


0

I think all you need is rsync For example: $ rsync -auxnv -T /temp/dir --exclude={"/dir/1","/dir/2",...} \ /source/file user@host:/dest/dir/ There is also an option for compression during transfer, -z Please read man rsync Check this too.


1

I thought that maybe as "@steeldriver" user said, the network couldn't have been ready yet when the system booted, hence I edited and added "sleep 120" before the command. Now it is "@reboot sleep 120; /path/to/my/script.sh > /home/myuser/itworks.txt 2>&1". It simply works, it creates the file itworks.txt and if you "cat" it, you'll get all the info.


0

You may invoke crontab as root, crontab -e and then insert this line @reboot /home/myuser/bin/command.sh where command.sh is the executable file note: chmod 755 command.sh


2

You need to either use tar --no-recursion or find ... ! -type d because each time your find is listing a directory, tar is recursively copying all of it. Also, couldn't you simply avoid the copy and do a -C dir . for each dir in your array, eg: args=() for f in "${folders_to_backup[@]}" do args+=("-C" "$f" ".") done tar -czf "/home/myuser/backup.tgz" "$...


0

Your cron job is receiving less resources, you can run it with a higher priority with: /usr/bin/nice --adjustment=-10 /path/to/cron-script Note the command above will reduce the resources of running services, so be careful using in production services.


0

It's the second. cron will send an e-mail when the job completes regardless of when it is. You can check this yourself by setting a crontab like this: */5 * * * * sleep 600; date You'll get an e-mail 10 minutes later every 5 minutes.


2

The email will be sent every time X.sh finishes running, whenever that is. cron itself will send a job's output by email by default, to the relevant crontab owner or whatever MAILTO is set to; you could use that instead of manually calling mail.


2

You could do this in several ways: Single cron entry 0 15 * * 6 job1; job2; job3 Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that. Multiple cron entries 0 15 * * 6 job1 0 15 * * 6 job2 0 15 * * 6 job3 Or as you ask, ...


0

Here is an explanation of the crontab format. # 1. Entry: Minute when the process will be started [0-60] # 2. Entry: Hour when the process will be started [0-23] # 3. Entry: Day of the month when the process will be started [1-28/29/30/31] # 4. Entry: Month of the year when the process will be started [1-12] # 5. Entry: Weekday when the process will be ...


3

The crontab entry you've written is equivalent to 0 0-23/12 * * * . /X.sh This requests execution on the hour between midnight and 11pm, using 12-hour steps — so cron will run the job every day at midnight and noon.


0

I faced the same problem and that is how I fixed it: First, try to find out why what is the error of your push. You can get the error log by adding 2>&1 at the end of your script. In your case it would be: ${GIT} push git@bitbucket.org:username/repo.git master >> ${LOG} 2>&1 Several reason can cause your push is not working from ...


1

You should be able to get this to run by putting in house.sh: export DISPLAY=:0.0 and running xhost + on your interface. Once that works you can restrict who is allowed to connect (using xhost again), but once things stop working you'll know how permissive you have to be. This will not work if you are not logged in. I there run firefox from a python ...


2

You can do this by defining a job which runs every hour on the hour, and sleeps for a random amount of time before running the command you're actually interested in. In your crontab: SHELL=/bin/bash 0 * * * * sleep $((RANDOM*3600/32768)) && command (You need to specify the shell, to ensure that $RANDOM is available. There are other ways of ...


2

Unless your script is not executable (fix that with chmod +x /root/backup_system.sh) or the crond isn't running, there's nothing obviously broken in your script that will prevent it from running. All of the commands you use (date, hostname, tar, and ls) should be in /bin, which should be in the default PATH....unless you've changed it in your crontab. The ...



Top 50 recent answers are included