Why is my shell script not running with cron?

Why is my shell script not running with cron?

If running reboot directly as a non-root user works when you’re logged in, it’s because your system is configured to allow users who are physically logged in to reboot the system. This works via Polkit. From a crontab, you aren’t in a logged-in session. A cron job that reboots the system would have to run as root.

What to do if Bash is not running via crontab?

To make sure it is, run the following command: Do crontab -e for whichever crontab you’re using and replace it with output of the above command. This should mirror most of your environment in case there is some missing path issue or something else. Also check logs for any errors it’s getting.

Why is cron job not running with same user?

The cron job doesn’t run with the same user with which you are executing the script manually – so it doesn’t have access to the same $PATH variable as your user which means it can’t locate the Java executable to execute the commands in the script. We should first fetch the value of PATH variable as below and then set it (export) in the script –

Can you run a script in Cron without Sudo?

Permissions are all fine on the script itself and it can be executed without using sudo. As I mentioned, it runs from the terminal just fine and works as designed. But if I put it in cron and remove the tun0 interface, nothing ever happens. Have you ever try debugging your script to see what happens when executed by cron?

Why is the ECHO command not working in cronjob?

If your cronjob’s $PATH environment variable does not include /bin, the echo command will fail. If this is the problem, the simplest solution is to explicitly set the path to ‘echo’ in your script.

What is the problem with my side of cron?

The issue is when i execute this script manually it works fine, but using cron the script not works. Using cron got the mail with the output of date command only. What is wrong with my side?

Why is cronjob not running in the terminal?

Working perfectly when I run that command in the terminal but it doesnt seem to be running from the cronjob. you need to specify the full path to the executable pwsh. you can do so by using which APPNAME in a terminal. then change the line in your crontab accordingly. for me the working result looks like this:

Is there a cron job that reboots the system?

A cron job that reboots the system would have to run as root. I don’t think rebooting is the solution to create a network interface. Just call whatever you do normally to bring up the VPN.

How to run PWSH script in Linux cronjob?

If you’re script has a #!/usr/bin/pwsh shebang & is executable it executes like any script without specifying ‘pwsh’ BTW if you’re displaying to screen, say a dialog, the cron job must be prefaced with env DISPLAY=:0 (or some other number) in order to display. eg env DISPLAY=:0 pwsh $ScriptHome/DiskFull-WereGoingToCrash.ps1 -display