Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

38 votes
11 answers
40068 views
Check if script is started by cron, rather than invoked manually
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts. How can I know if the Bash script is started by cron ?
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts. How can I know if the Bash script is started by cron ?
daisy (55777 rep)
Aug 31, 2012, 09:07 AM • Last activity: Aug 1, 2025, 12:17 PM
2 votes
2 answers
2425 views
Skip syslog/rsyslog logging of certain cron jobs
In most GNU/Linux distributions the default is to log start (and many different events) of every cron job to syslog. It's rather convenient, but not for a very frequent jobs, which started, say, every 1 minute. I know how to redirect all cron jobs events to a different log via `/etc/rsyslog.conf` (`...
In most GNU/Linux distributions the default is to log start (and many different events) of every cron job to syslog. It's rather convenient, but not for a very frequent jobs, which started, say, every 1 minute. I know how to redirect all cron jobs events to a different log via /etc/rsyslog.conf (*.*;cron,auth,authpriv.none -/var/log/syslog) and it's easy to heavily restrict the logging to, say, just error events via /etc/default/cron (EXTRA_OPTS="-L 4"). But this affect all of cron jobs. What if I want to restrict the logging of *certain* cron jobs (said frequent every-1-minute jobs)? Is it possible to set this up via /etc/rsyslog.conf or in /etc/crontab itself? The system is Debian 8.0 Jessie.
Neurotransmitter (3071 rep)
May 14, 2015, 09:35 PM • Last activity: Jul 31, 2025, 03:08 PM
0 votes
2 answers
1879 views
Unix 11i v2 Script to detect new files within directory
I was hoping someone can point me in the right direction. I would like to create a script to check for new files (files with today's date) within a directory and then print the results to a text file. Could I use `cron` or `bash`? edit: Updated original thread. I tried the following on my Linux Mint...
I was hoping someone can point me in the right direction. I would like to create a script to check for new files (files with today's date) within a directory and then print the results to a text file. Could I use cron or bash? edit: Updated original thread. I tried the following on my Linux Mint VM and I got it to work. The only problem is: 1) when i create a new file (using "sudo vi newtextfile.txt" and then ":w") i receive the notification email *4 times*. 2) am i triggering multiple IN_CREATE events by creating a new file using the method i mentioned above? /xyz/jon >>> total 12 786436 drwxr-xr-x 2 root root 4096 Jul 13 20:43 . 786434 drwxr-xr-x 4 root root 4096 Jul 13 19:45 .. 786441 -rwxr-xr-x 1 root root 48 Jul 13 20:32 mylogger.sh 786437 -rw-r--r-- 1 root root 0 Jul 13 20:22 mylogtoday.txt "incron.table-jonincron" >>> /xyz/client IN_CREATE /xyz/jon/mylogger.sh /xyz/jon/mylogger.sh >>> sudo mail -s "testing script" emailaddress@domain.com
jes516 (863 rep)
Jul 13, 2014, 09:01 PM • Last activity: Jul 28, 2025, 10:01 PM
0 votes
2 answers
3178 views
multiple schedules for a single task in a k8s cronjob
**Warning**: k8s greenhorn on this side. I need to run a task that will be set up in a k8s cronjob. I need it to run every 45 minutes. Having this in the `schedule` does not work: 0/45 * * * * Because it would run at `X:00`, then `X:45` then `X+1:00` instead of `X+1:30`. So I might need to set up mu...
**Warning**: k8s greenhorn on this side. I need to run a task that will be set up in a k8s cronjob. I need it to run every 45 minutes. Having this in the schedule does not work: 0/45 * * * * Because it would run at X:00, then X:45 then X+1:00 instead of X+1:30. So I might need to set up multiple schedule rules instead: 0,45 0/3 * * * 30 1/3 * * * 15 2/3 * * * I am wondering if it's possible to set up multiple schedules in a _single_ CronJob definition or if I will have to setup multiple CronJobs so that each CronJob takes care of each line. https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/cron-job-v1/ **Update**: I just read that it's possible to have more than a single manifest written in a single yaml file so it might work with 3 manifests.... but knowing if it's possible with a single manifest would be awesome.
eftshift0 (707 rep)
Oct 28, 2021, 03:12 PM • Last activity: Jul 21, 2025, 06:07 PM
1 votes
1 answers
353 views
On my Ubuntu-based distro (Linux Lite), how to auto delete all network connections, disable Wi-Fi and networking as part of booting process?
My end goal here is to have no saved network connections, no enabled Wi-Fi or networking each time I boot up my computer, so that I have to go through a sequence of steps in order to access internet. The purpose is to moderate my sceen behavior. My current way is through creating a script that uses...
My end goal here is to have no saved network connections, no enabled Wi-Fi or networking each time I boot up my computer, so that I have to go through a sequence of steps in order to access internet. The purpose is to moderate my sceen behavior. My current way is through creating a script that uses 'nmcli' and run at startup using crontab's @reboot. But It's not working. Here is the script
#!/bin/bash

# this script disables wifi and networking

echo 'Deleting all existing connections...'
# nmcli is a command-line interface for networkmanager
# 'nmcli connection delete' -> simply deletes a connection by ID, UUID or others
# we use 'nmcli connection show' along with some filter to extract UUIDs for all conections
# TODO enable deletion of a particular connection
#connections_list=$(nmcli connection show | grep -oP '\s(\S+-\S+-\S+-\S+-\S+)\s')
#for connection in "$connections_list"; do 
    #nmcli connection show "$connection"
    #if (($? != 0)); then 
        #echo "something went wrong while deleting connection $connection" >&2
        #exit 1
    #fi
#done
nmcli connection delete $(nmcli connection show | grep -oP '\s(\S+-\S+-\S+-\S+-\S+)\s') 
if [[ $? -ne 0 ]]; then
    echo 'shit happens while deleting connections' >&1 
    exit 1
fi
echo 'All connections were deleted! now, you will have to type SSID and password again'

echo 

echo 'Disabling Wi-Fi...'
if ! nmcli radio wifi off; then 
    echo 'nmcli, command disabling wifi, is not satisfied for some reason' >&2
    exit 1
fi 
echo 'Wi-Fi is disabled.'

echo 

echo 'Disabling networking...'
if ! nmcli networking off; then 
    echo 'nmcli, command disabling networking, is not happy' >&2 
    exit 1
fi
echo 'Networking is disabled.'

echo

echo 'All is good'
echo '==============================='
exit 0
Here is the corntab line (created using sudo crontab -e) @reboot /home/noor/bin/go-offline-1.0 >> /home/noor/go-offline.log 2>&1 Contents of log file:
Deleting all existing connections...
Error: NetworkManager is not running.
Error: NetworkManager is not running.
shit happens while deleting connections
I guess that at the point of executing my script in the boot process, NetwrokManager is not yet activated. Also after a quick exchange with ChatGPT, I tried to make script run as part of the shut down process rather than at startup using systemlc or sth, but it didn't work for some reason. I don't see reason to mention its details. I had an idea to alias poweroff command so that it executes my script then shut down the computer. I don't know whether it's a good idea but I am looking for a better solution anyway. I welcome all useful responses related to any part of this, including fixes to this method or completely different approach. Thank you!
mark coder (49 rep)
Jul 21, 2025, 11:14 AM • Last activity: Jul 21, 2025, 12:25 PM
-2 votes
1 answers
93 views
Linux command does not run from crontab, but it runs fine from the Linux shell
I set up the following cron job to check every minute if port 8088 is listening. If it isn't, the CLI should write the message Thu Jul 3 12:50:09 UTC 2025 bad to the log file `/tmp/crob_log`. Here is the cron entry: crontab -e * * * * * root wget http://DB_SERVER_we:8088 ; [ $? -ne 0 ] && echo `date...
I set up the following cron job to check every minute if port 8088 is listening. If it isn't, the CLI should write the message Thu Jul 3 12:50:09 UTC 2025 bad to the log file /tmp/crob_log. Here is the cron entry: crontab -e * * * * * root wget http://DB_SERVER_we:8088 ; [ $? -ne 0 ] && echo date bad >> /tmp/crob_log However, the cron job always logs the "bad" message, even though the exit status from wget http://DB_SERVER_we:8088 is 0. When I run the same command manually on the Linux machine, it works fine (no "bad" message), which is the expected behavior. But when it runs from cron, it always logs "bad". So, what's wrong with the command line in the crontab?
yael (13936 rep)
Jul 3, 2025, 12:57 PM • Last activity: Jul 3, 2025, 05:57 PM
0 votes
3 answers
207 views
Alpine linux (LXC) not running cron jobs
I have been trying for a long to make the crontab entries to run, but it doesn't matter what Time / schedule I enter, it doesn't seem to work. I have confirmed my current time zone with `date` command & `/etc/localtime` for the symbolic link. How do I know that cron is not working? My script calls $...
I have been trying for a long to make the crontab entries to run, but it doesn't matter what Time / schedule I enter, it doesn't seem to work. I have confirmed my current time zone with date command & /etc/localtime for the symbolic link. How do I know that cron is not working? My script calls $date (date and time or running) in it to print within the output log, but when I modify the crontab entry to a specific time, it doesn't reflect that time, only the time of last manual execution. Furthermore, I know that the script does run as I have run it manually and verified the output log, so it's not due to triggering a script error. Yes, rc-service crond restart has also been applied. Someone, please suggest any avenue to investigate or troubleshoot further. Here is my crontab entry, please ignore the 'weekly' naming. Redacted timezone entries are Continent/Timezone crontab entry Here I am providing the script, as there is a suspicion regarding this --- This is under **root** cron so privileges are not an issue. #!/bin/sh # Log file for updates LOG_FILE="/var/log/alpine_weekly_update.log" echo "--- $(date) ---" >> "$LOG_FILE" echo "Starting Alpine Linux weekly update..." >> "$LOG_FILE" apk update >> "$LOG_FILE" 2>&1 apk upgrade >> "$LOG_FILE" 2>&1 # &1 is to differentiate from a file name(str or int) but as a desctiptor, here it will redirect both the stderr,and stdout to the logfile # Check for kernel updates: if [ -f /var/run/reboot-required ]; then echo "Reboot required after update. Rebooting Now" >> "$LOG_FILE" reboot fi echo "Alpine Linux weekly update finished." >> "$LOG_FILE" echo "-----------------" >> "$LOG_FILE" ---------------------------------------------------- Update: After a whole day of troubleshooting with this deployment, I did not managed to figure out the fault, except that I had installed **Cornie** in that which is causing a conflict. Synopsis: - syslog-ng was running and logging (installed, not a default). - crond was confirmed running (by rc-service crond status). - crontab entry was valid and present for root. - Ownership (chown), Mode (chmod) and UID, GID all are in favour of root in the Script, log and cron (cornie-service / crond) - crond was NOT sending any CRON messages to syslog-ng, even after explicit restarts - Installed and reinstalled Cornie, Deleted the .Pid files (/run/cronie.pid ; /var/run/cronie.pid) ---------------------------------------------------------- I spun off another alpine (3.21, previous was the same) and became very surprised by this -- Here I didn't install Cornie, but **no entry** on the crontab which had a **specific time** mentioned, did work. For example if I wanted to run each day 12:30AM (30 12 * * * /path/to/script). However, when I put the schedule of running every minute (* * * * * /path/to/script) it ran properly. And I want to mention, that no declaration of path (PATH=) or Time zone / TZ (which was my primary suspicion) was provided, yet the each minute implementation was working. Furthermore I didnt even re-load the rc-services. At this point I dont think there is any point going further, as most probably the busybox itself has some flaws or the cron has some other deep issues.
Neail (79 rep)
Jun 21, 2025, 03:25 PM • Last activity: Jun 28, 2025, 07:17 AM
3 votes
2 answers
2217 views
crontab command fails to create temporary directory
On two of my VMs the `crontab -e` command fails to create a directory in `/tmp` but it works with `mkdir`: ``` /tmp/crontab.oxyaBy: Input/output error Creation of temporary crontab file failed - aborting ``` strace output: ``` root@vm:~# strace crontab -e mkdir("/tmp/crontab.1SuJe9", 0700) = -1 EIO...
On two of my VMs the crontab -e command fails to create a directory in /tmp but it works with mkdir:
/tmp/crontab.oxyaBy: Input/output error
Creation of temporary crontab file failed - aborting
strace output:
root@vm:~# strace crontab -e
mkdir("/tmp/crontab.1SuJe9", 0700)      = -1 EIO (Input/output error)

root@vm:~# strace mkdir /tmp/crontab.1SuJe9 -m 700
mkdir("/tmp/crontab.1SuJe9", 0700)      = 0
Both VMs are running Ubuntu 16.04.6 LTS (4.4.0-173-generic x86_64) This is reproducible every time and the problem persists after reboots, fsck says everything is fine and there are no other issues on this VMs. I already tried to reinstall the cron package but nothing changed. Any ideas? Thank you! **Edit:** dmesg shows
EXT4-fs (dm-0): Quota write (off=4080, len=40) cancelled because not block aligned
Quota error (device dm-0): v1_commit_dqblk: dquota write failed
The crontab command works with quotaoff but I still would love to know why crontab and mkdir behave differently...
Anatol - user3173842 (143 rep)
May 4, 2020, 12:43 PM • Last activity: Jun 24, 2025, 08:07 AM
44 votes
4 answers
102877 views
Cron log on debian systems
On Redhat systems cron logs into `/var/log/cron` file. What is the equivalent of that file on Debian systems?
On Redhat systems cron logs into /var/log/cron file. What is the equivalent of that file on Debian systems?
xralf (15189 rep)
Apr 21, 2011, 12:29 PM • Last activity: Jun 19, 2025, 11:53 PM
0 votes
2 answers
2340 views
Monitor process pid for change
I have a service that is always supposed to be running. I’d like to know when the service ever stops or gets restarted. I’ve thought about referencing the service’s PID. If it gets restarted, it would get a new pid. So I would like to send an alert or email whenever the pid changes. What’s the least...
I have a service that is always supposed to be running. I’d like to know when the service ever stops or gets restarted. I’ve thought about referencing the service’s PID. If it gets restarted, it would get a new pid. So I would like to send an alert or email whenever the pid changes. What’s the least intrusive way to do this? Right now I have a cron job writing the pid to a file every 5 minutes. Is there a Linux tool that can monitor this file for pid changes? Or should I have some other thing like a Python script running outside somewhere that can pull this file and monitor that way?
Vince (1 rep)
Mar 28, 2019, 11:13 PM • Last activity: Jun 19, 2025, 10:04 AM
1 votes
3 answers
2046 views
Why is this update script not executing from cron?
I simply want a script that runs a few update commands. I want them to happen at 3am every day. I cannot figure out why they don't work. I added this like to crontab -e 0 3 * * * root /etc/cron.custom/update The script in the update file is #!/bin/bash # if not root, run as root if (( $EUID != 0 ));...
I simply want a script that runs a few update commands. I want them to happen at 3am every day. I cannot figure out why they don't work. I added this like to crontab -e 0 3 * * * root /etc/cron.custom/update The script in the update file is #!/bin/bash # if not root, run as root if (( $EUID != 0 )); then sudo /home/jb/bash/update.sh exit fi apt-get update dietpi-update apt-get -y upgrade apt-get -y dist-upgrade apt-get clean apt-get -y autoremove reboot I don't know how to make scripts so I found that off the internet. It is surprisingly hard to find any answers on how to edit anything to do with cron. Unattended upgrades doesn't upgrade everything so before anyone recommends it I tried it already and it missed heaps constantly. In short how do I auto update and upgrade my device? Running Debian (DietPi).
Ashley Forrest (11 rep)
Mar 16, 2017, 05:24 AM • Last activity: Jun 10, 2025, 10:03 AM
2 votes
0 answers
9891 views
Cron stopped logging to /var/log/cron.log
A month ago I set cron to log to `/var/log/cron.log` by modifying `/etc/rsyslog.d/50-default.conf`. Logging worked great until I changed permissions on `/var/log` (by easing permission restrictions), and forced logrotate to rotate the logs by executing `logrotate --force /etc/rsyslog.d/50-default.co...
A month ago I set cron to log to /var/log/cron.log by modifying /etc/rsyslog.d/50-default.conf. Logging worked great until I changed permissions on /var/log (by easing permission restrictions), and forced logrotate to rotate the logs by executing logrotate --force /etc/rsyslog.d/50-default.conf. Since then, cron seems to have stopped logging. There is no longer a /var/log/cron.log. I executed sudo touch /var/log/cron.log to create it, but it has remained 0 bytes since. More details on what I did with the permissions: I ran sudo chmod 775 /var/log, and subsequently changed permissions back with sudo chmod 755 /var/log. All other services appear to be logging correctly, and cron jobs are actually running (verified with ps aux | grep rsync, since I only run rsync via cron). I wasn't sure of the correct user and group access rights for cron.log so I tried changing it to syslog:adm like most of the other log files, but that didn't help, so I switched it back to root:root, Current permissions on cron.log: -rwxr-xr-x 1 root root 0 Apr 27 16:34 cron.log Not sure where to go from here. I know I can have cron log to any file I'd like (either by adding >> /path/to/logfile to end of cron job entries or by editing /etc/rsyslog.d/50-default.conf), but for consistency, I would prefer it continue logging to cron.log. I suppose I could add >> /var/log/cron.log to the end of each cron entry, but that seems a little hacky to me. EDIT: As per my comment below, I changed the log location to /tmp/cron.logand logging has resumed. At first, I had assumed this implied that either the folder or file permissions are wrong. However, I checked them against another machine running the same distro, and the folder permissions were correct. The file permissions were not restrictive enough, the correct permissions can be set with sudo chmod 640 cron.log. As a test, I deleted the empty cron.log, and it was never recreated. I modified the rsyslogd config to have it log to crond.log, but the file was never created.
philosophie (875 rep)
Apr 28, 2016, 03:24 PM • Last activity: Jun 9, 2025, 03:06 AM
16 votes
1 answers
2847 views
cron every thirty minutes from 13:00 to 17:00 seems easy, but the obvious entry also runs it at 17:30
cronie 1.5.2 on RHEL 8.10 This entry runs foobar every 30 minutes from 13:00 to 17:30. */30 13-17 * * 1-5 foobar.sh Is there some clever (but not hackish, like adding "exit if it's 17:30" to the script) way to get it to not run at 17:30, or is brute force (two crontab entries) the best way? */30 13-...
cronie 1.5.2 on RHEL 8.10 This entry runs foobar every 30 minutes from 13:00 to 17:30. */30 13-17 * * 1-5 foobar.sh Is there some clever (but not hackish, like adding "exit if it's 17:30" to the script) way to get it to not run at 17:30, or is brute force (two crontab entries) the best way? */30 13-16 * * 1-5 foobar.sh 0 17 * * 1-5 foobar.sh
RonJohn (1421 rep)
Jun 1, 2025, 08:32 PM • Last activity: Jun 2, 2025, 05:05 PM
-1 votes
1 answers
35 views
Merge two different times in cron format
I want to combine two different times which are in cron format into single time in bash shell script: e.g. ``` time1 = 15 03 * * 1-5 time2 = 15 03 * * 6 ``` result should be ``` 15 03 * * 1-6 ``` or e.g. ``` time1 = 00 05 * * 1-3 time2 = 00 05 * * 3-5 ``` result should be ``` 00 05 * * 1-5 ``` I can...
I want to combine two different times which are in cron format into single time in bash shell script: e.g.
time1 = 15 03 * * 1-5 
time2 = 15 03 * * 6
result should be
15 03 * * 1-6
or e.g.
time1 = 00 05 * * 1-3 
time2 = 00 05 * * 3-5
result should be
00 05 * * 1-5
I can ignore time part for now and only consider day of the week.
Vishal (1 rep)
May 20, 2025, 12:39 PM • Last activity: May 20, 2025, 12:56 PM
0 votes
1 answers
5600 views
connect() to unix:///tmp/uwsgi_dev.sock failed (2: No such file or directory) while connecting to upstream
I tried to run django application using uwsgi+nginx and the cronjob command is, `* * * * * /usr/local/bin/lockrun --lockfile /path/to/lock_file -- uwsgi --close-on-exec -s /path/to/socket_file --chdir /path/to/project/folder/ --pp .. -w project_name.wsgi -C666 -p 32 -H /path/to/virtualenv/ 1>> /path...
I tried to run django application using uwsgi+nginx and the cronjob command is,
* * * * * /usr/local/bin/lockrun --lockfile /path/to/lock_file -- uwsgi --close-on-exec -s /path/to/socket_file --chdir /path/to/project/folder/ --pp .. -w project_name.wsgi -C666 -p 32 -H /path/to/virtualenv/ 1>> /path/to/success_log 2>> /path/to/error_log
but I receive the error in nginx error log file as,
**019/11/20 06:45:21 [crit] 1986#1986: *2 connect() to unix:///path/to/socket_file failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xx.xxx, server: localhost, request: "GET /auth/status/ HTTP/1.1", upstream: "uwsgi://unix:///path/to/socket_file:", host: "xx.xxx.xx.xxx", referrer: "http://xx.xxx.xx.xxx/ "**
the path for the socket_file in nginx configuration file and in cronjob command is same, can any one have idea where I'm making the mistake???
aji prabhakaran (1 rep)
Nov 20, 2019, 07:00 AM • Last activity: May 18, 2025, 02:07 AM
1 votes
1 answers
2344 views
cron to delete after executing
I have a `cron` job which unzips a file and executes it. The `cron` is set to unzip, execute and delete the .zip file after. It's executing fine but it's not deleting the file. Here's the `cron`: /usr/bin/wget -q -nd --delete-after 'URL/index.php?option=com_fwrealestate&task=processPlugin&plugin=imp...
I have a cron job which unzips a file and executes it. The cron is set to unzip, execute and delete the .zip file after. It's executing fine but it's not deleting the file. Here's the cron: /usr/bin/wget -q -nd --delete-after 'URL/index.php?option=com_fwrealestate&task=processPlugin&plugin=importmls' I tried to add a second cron which would delete the files that are older than 15 days from the folder but this seems to "bother" the first cron to execute properly. The second cron I used was:
/usr/bin/find /directory/ -mtime +15 -exec /bin/rm {} \; > /dev/null 2>&1
Petros (11 rep)
Oct 17, 2012, 08:21 PM • Last activity: May 15, 2025, 07:14 PM
2 votes
4 answers
229 views
Executing a cron task once a month at a random date and time
Ubuntu 22.04 or AlmaLinux 9.5 I've seen a lot of questions about running scripts in random times during a day using bash's $RANDOM but a month exceeds the limit it has. How can I do that? It is a `xdg-open`command to be executed no more than twice a month (exceptionally more in case of power off), a...
Ubuntu 22.04 or AlmaLinux 9.5 I've seen a lot of questions about running scripts in random times during a day using bash's $RANDOM but a month exceeds the limit it has. How can I do that? It is a xdg-opencommand to be executed no more than twice a month (exceptionally more in case of power off), any day, any time, random, not the same date every month. The time between 2 consecutive tasks must not be more than 30 days.
Daniel Stonek (21 rep)
Apr 29, 2025, 12:33 AM • Last activity: May 14, 2025, 01:02 PM
11 votes
2 answers
5990 views
Using Cron to restart a systemd user service
I have created a --user service in systemd such that a non privileged user can manage a service. This works well. I wanted to restart the service at a fixed given time of day, so i created a cron job in the users crontab. Strangely this does not work. The user can restart the service if they run: sy...
I have created a --user service in systemd such that a non privileged user can manage a service. This works well. I wanted to restart the service at a fixed given time of day, so i created a cron job in the users crontab. Strangely this does not work. The user can restart the service if they run: systemctl --user restart myservice.service However running this from the crontab does not restart the service. Does anyone know why? This is running on Ubuntu 16.04.
Magnus Jørgensen (113 rep)
Oct 10, 2018, 08:30 AM • Last activity: Apr 28, 2025, 07:05 PM
0 votes
3 answers
357 views
save the output to multiple files in crontab
There is a script scheduled in crontab. ``` 0 2 * * * /usr/local/bin/backup.sh >> /root/output_all.txt ``` I want to save the output into multiple files like output_all.txt and output_date.txt at the same time. I know there is ```tee``` command to save the output to the multiple files. But ```tee```...
There is a script scheduled in crontab.
0 2 * * * /usr/local/bin/backup.sh >> /root/output_all.txt
I want to save the output into multiple files like output_all.txt and output_date.txt at the same time. I know there is
command to save the output to the multiple files.
But
can be used only when tty exists? Is there any other solution?
Hardguy (59 rep)
May 29, 2023, 10:12 PM • Last activity: Apr 15, 2025, 01:09 PM
1 votes
1 answers
4318 views
Run python code from cron in an Anaconda environment
I need to run a python script using a specific anaconda environment, since I need to execute this script several times per day I would like to do it using the linux crontab file (/etc/crontab). When I launch the script from the linux command line it works fine: ~/anaconda2/envs/py36/bin/python ~/pro...
I need to run a python script using a specific anaconda environment, since I need to execute this script several times per day I would like to do it using the linux crontab file (/etc/crontab). When I launch the script from the linux command line it works fine: ~/anaconda2/envs/py36/bin/python ~/production/web_scraping.py I added the process to the crontab file: SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 57 08 * * * user ~/anaconda2/envs/py36/bin/python ~/production/web_scraping.py | touch ~/test.txt The line is correctly executed by cron, this is the cron log: user@exmachina:~$ sudo cat /var/log/syslog | grep web_* Jan 2 08:57:02 localhost CRON: (user) CMD (~/anaconda2/envs/py36/bin/python ~/web_scraping.py | touch ~/test.txt) I added | touch test.txt to the cron line to ensure the line is executed, and the *test.txt* file is generated. The python script uses Selenium to extract data from a web page, by means of the chrome webdriver. Can this be the reason the script runs fine from the command line but not from the cron file? Thanks for your help!
jordi vidal (11 rep)
Jan 2, 2018, 10:42 AM • Last activity: Apr 15, 2025, 02:04 AM
Showing page 1 of 20 total questions