New answers tagged

2

Does /temp really exist (didn't you mean /tmp)? If it doesn't then your script tries to cd to /temp, fails, and then all the commands run in the starting directory. The last two commands are particularly dangerous because you cd to /, then cd to /temp (which may not exist) and then rm everything (which could well be the root filesystem). You should ...


1

In my opinion you should never ever disable the root user entirely. If you do not want to be able to login as root using ssh you should set the directive PermitRootLogin no in /etc/ssh/sshd_config. For other applications there are mostly equivalent settings which can be made.


0

Expanding on @Cyrus answer this is what I did: I made a script which checked a UTC offset: #!/bin/bash export TZ=":US/Eastern" if [ "$(date +%z)" == "$1" ]; then shift exec $@ fi Then I add two crontab entries each for the offset I want: 0 8 * * * run-only-with-tz.sh -0400 place_your_command_here 0 9 * * * run-only-with-tz.sh -0500 ...


1

Here are some points about those two (hope would answer your questions): 1. checking what your cron job really does can be kind of a mess, but all systemd timer events are carefully logged in systemd journal like the other systemd units based on the event that makes things much easier. 2. systemd timers are systemd services with all their ...


2

The entries are added to the log each time a cron job runs. To reduce the time between entries, you would have to look at your cron jobs and change their timings. This, though, may break something that relies on those jobs running at specific intervals. If they really do annoy you, then simply follow the instructions on the Debian bug report and stop cron ...


3

Solution to the problem is to modify the entries in cron with the absolute path names. Added cron command logging capability as the machine doesn't have an MTA to send failure notifications, as follows: 0 0 * * * /usr/local/bin/bitcoind -datadir=/home/pi/bitcoinData -daemon >> ~/bitcoinData/bitcoin-cron.log 2>&1 0 6 * * * ...


2

Applications run from cron have no "console". Both stdout and stderr are captured and emailed to the local user account when the job completes. In your case the script is run as root, so the result will in in root's email. As for writing to the file, the ~ represents the root user's home directory, i.e. /root, so that is where you need to look for the ...


3

There are several places where cron-jobs are stored. The main place, is /etc/crontab (and on some systems, this is the only one). This file is edited only by root, and often allows to specify which user the job should run as. On some systems, there is also a directory - /etc/cron.d - which complement /etc/crontab. The files here contains line(s) like ...


0

The only difference between using COPY and RUN are the permissions on the /etc/crontab file: with COPY this is 664 and with RUN 644. I cannot find anything on permissions that /etc/crontab needs to have but if you add RUN chmod 644 /etc/crontab after the COPY line in your Dockerfile the cronjobs run (at least for me). So I think the permissions have to ...


0

Why you didn't try to edit /etc/rsyslog.conf ?! As you know you can force rsyslog to log service that hasn't specific logger. So I suggest read man rsyslog.conf to know how make service making log and edit the service to send logs here ( edit somewhere like /etc/init.d/rsyslog to configure log section ).


0

The issue wasn't rooted in sendmail at all. Using pstree, I was able to determine that there were many more processes that were also hanging, not terminating, and parented by crond. I looked through each of these processes and discovered that one process was doing something along the lines of cat /var/log/some_log_file When I did ls /var/log/some_log_file, ...


1

try: #!/bin/bash while true; do for user in $(ls /home); do chgrp www-data /home/${user}/private/FILE.TXT done sleep 10 done The infinite loop is for bypassing the cron limitation of 1 minute to repeat a job. make it executable: chmod +x /PATH/TO/owner.sh And just run it without a cronjob. Also if you just want to react to the ...


1

cron intentionally runs with a limited environment (including a restricted path, it does not have the same path as your standard shell). You either need to run a script (including the full path to the script) which then sets a path variable internally, or you need to set the path in the crontab line itself. One example of that is, 12 0 * * * (export ...


1

As long as you get the script right and you don't run it in a weird environment, everything should be fine. But if something breaks the expected output of date, all bets are off. For example, if you run this snippet with IFS=-, then you'll be running something like rm /media/… 04 26* i.e. delete files beginning with 26 in the current directory. Of course ...


1

Since there is always a space in your filenames, I'd include that in your command: rm "$(date +%F --date "Yesterday") "* # Removes old clips That should be an easy way to prevent deleting all files in the directory, as even if date doesn't return anything, it would only delete files starting with a space character (which hopefully do not exist). However ...


2

Two things jump out: You have no checking for failure of the substitution There is a race condition if the date changes between uses of the date command. You could solve them both like this: #/bin/bash # Exit if any command fails set -e dir='/media/jmartin/Cams/video' day=$(date +%F --date Yesterday) # Conbine files from the past 24 hours into a ...


5

The $(date +%F --date "Yesterday") technically isn't a variable, it's a command substitution, but that is tangential to your question. This construct could prove to be problematic if for some reason the date command wasn't in your $PATH, and thusreturned nothing - at which point it would delete everything in /video/. If you instead take that command ...


1

I've found an answer in "How Linux Works" by Brian Ward. I've simply messed the syntax. Deleting the passing of $USER fixed the problem. In other words the file file I am passing to crontab should have following structure: m h dm m dw command and not: m h dm m dw user command And again thank you roaima for useful tips.


0

When writing cron jobs you should use the absolute path to the binary, if you haven't already done a export of your PATH in crontab. Find out where lsyncd is located with: $ command -v lsyncd Example output: /bin/lsyncd. Copy the output and replace lsyncd with the absolute path. Give this a try, I hope it helps.


0

While setting variables like this in a cron entry is not possible, what crontab will allow you to do is override the MAILTO variable for a single entry then set it back for subsequent entries. Example: # Eat Ham * * * * * /scripts/manga_ham.py MAILTO=porklover.cramble.edu #Do something * * * * * /scripts/chown_abrahams_niece.sh MAILTO=root As a down ...


1

The syslog format typically contains a timestamp, hostname, app name, and process ID along with whatever custom message was sent. All of these values are (substantially) under the control of the process that sends the syslog message. The cronie source (if configured to use syslog) uses the openlog and syslog functions to write to syslog. Seeing that the ...


0

For those on Linux who are comfortable installing Python packages, I just released a nootify-send-headless program which is working well for me. It searches /proc for the required username and environment variables and then runs notify-send with these variables (it will use sudo to switch to the required user if necessary).


0

If you mean hacking the standard email that cron emits when a job fails, then you cannot to this without modifying cron. You can emit HTML (or even multipart/alternative) from your script if you want, but it won't change the fact that cron will send it as a text/plain body. I suggest that you wrap your cron jobs in an outer adaptation script that does this ...


3

Sunday is 0, Monday is 1, etc. http://man7.org/linux/man-pages/man5/crontab.5.html The time and date fields are: field allowed values ----- -------------- ... day of week 0-7 (0 or 7 is Sunday, or use names)


-1

If you are entering your service name correctly, I think your problem causes from lack of Environment Variables. From service command manual: service runs a System V init script in as predictable environment as possible. It's better to use full path of your service file like: /etc/init.d/network-manager Therefor for restarting your service use: ...


1

The simplest answer to check if a cronjob works when you expect it to (short of reading the man page) would be to add a simple cronjob that will report the date to a particular file: 0 * * * * date >> /tmp/cronjob.test Then check it the next day (or whenever) and ensure it's triggering when you expected it to. I personally would recommend reading ...


0

So it looks like cron doesn't have any logging or debug option. To check that your short script is run as expected, you could watch strace -f -p $(pgrep cron) in a terminal window. Run strace -f my-basic.sh in advance so you know what it should look like. If a cron script generates any output, it should be mailed to your user. When you open a terminal it ...


0

You may make take the advantage of OBJECT IDLETIME command, which returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations). example code as follows: #!/bin/sh redis-cli -p 6379 keys "*" | while read LINE ; do val=`redis-cli -p 6379 object idletime $LINE`; if [ $val -lt $((30 * 24 * 60 * ...


1

I use either script2log (simple), or vile-pager (vi like emacs) for this sort of thing. The script handles overstrikes of the sort mentioned, as well as backspace/overstriking. To handle cursor-movement (as you would get in editing a command-line), a simple script like this is not adequate. The script removes ANSI-style escape sequences, however. The ...


0

Trivially, assuming there are no vt100 escapes to handle, you might try pushing the output through sed 's/\r$//; s/.*\r//' or the awk equivalent awk '{ sub("\r$",""); sub(".*\r",""); print}' but this assumes your sed or awk can handle very long lines, as the carriage-returns obviously aren't newlines. Also, carriage-return only moves the cursor to the ...


5

The default behaviour of wget (documented in the manual) is to restart after a default timeout of 900s (aka 15 min). Adding --timeout=0 solves the problem here.


0

Regarding the script: make sure the script has execute permissions (chmod u+x /home/myUser/Downloads/ascript.sh)? Regarding the useradd statement: does this make sense? You're creating a duplicate user with the same UID and GID as root!


2

First we need to generate the folders we can put scripts in: mkdir ~/.config/cron.hourly mkdir ~/.config/cron.daily mkdir ~/.config/cron.weekly mkdir ~/.config/cron.monthly mkdir ~/.config/cron.yearly mkdir ~/.config/cron.reboot Then we need to run crontab -e to edit our scheduler. If this is you're first time running crontab, you'll need to select your ...


1

cron typically runs things in a fairly minimal environment (man 5 crontab to see what exactly), which probably doesn't have enough in its path for this. If you want to see what is in the path, you can always run printenv > /tmp/cron_env from (presumably at a time in the near future) to see. Generally you can just define an updated PATH in your crontab ...


2

Logs probably go to syslog, which varies depending on what syslog daemon is involved and how that is configured to log, start with grep -r cron /etc/*syslog* to find where and what is going on on the system, or per derobert under systemd the relevant command is journalctl -b 0 _SYSTEMD_UNIT=cron.service Adding a test cron job that touches a file ...


2

You can ask for the elapsed time in seconds: ps -p $$ -o etimes= This will always be accurate and comparable, regardless of what the system thinks the current time is. You can turn it into an unchanging start value by subtracting it from the current uptime (stored in seconds as the first value in /proc/uptime): echo $(($(cut -d. -f1 < /proc/uptime) - ...



Top 50 recent answers are included