Why is Bash using cron with SSH keys?

Why is Bash using cron with SSH keys?

I am using a cron script that rsyncs with a server via ssh. The commands work great when I run them directly as a bash script, but when I run them as cron, cron logs out bad permissions. I think this is because the cron user does not have access to the ssh key. Can I pass the ssh key into the cronfile, or into the script itself?

Can you run cron with different user ID?

For the second option, and assuming that your cron job runs with the correct user (otherwise there are more things to set correctly in your environment), just run: The user id might be different for you.

Where do I put my Cron crontab script?

You should use the full path to your executables and explicitly set any environment variables and PATH that they need. By the way, you don’t really have your script in the root directory do you? Also, /tmp is a directory that should already exist. You should create your output as a file within it as I’ve shown.

Why does CRON not run from the terminal?

If it is not, of course the “-l” parameter has to be changed accordingly. Things that won’t run from cron but will run from the terminal are almost always a problem due the difference in environment. You should use the full path to your executables and explicitly set any environment variables and PATH that they need.

How to add a cron job in Linux?

Cron is one of the most useful tools in a Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory. cru command syntax to add, list, and delete cron jobs

How to add cron job on ASUSWRT Merlin WiFi router?

And there you have it, I just add cron job on Asuswrt Merlin Wifi Router. You can create scheduled tasks using the standard crond service that runs on the router. You can put your cron tasks in /var/spool/cron/crontabs/. The file must be named “admin” as this is the name of the system user.

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 –

Why is my bash script not running with crontab?

In my case, the issue was that the script wasn’t marked as executable. 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.

How to run ssh-add from a script?

Plain-quoting ssh-agent doesn’t do anything, you need to incorporate the results of running it by using command substitution with: This causes the script to set the needed environment variables. However, ssh-agent still will not have any keys unless you ssh-add them. If your keys have no passphrase, then ssh-add can simply be run from the script.

Can you run a remote script from crontab?

The remote server solaris9 sparc has exactly the same version ssh installed. When I run this from the command line it runs without any issues and the remote script is executed. However I have inserted my script to my crontab file and the ssh command is executed as I can see the process but it never completes.

What’s the version of SSH for solaris9 SPARC?

SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0. The remote server solaris9 sparc has exactly the same version ssh installed. When I run this from the command line it runs without any issues and the remote script is executed.