Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating cron entry on server using ssh login within shell script

Tags:

bash

shell

cron

I need to upload a file (bash script) to a remote sever. I use the scp command. After the file has been copied to the remote server I want to create a cron entry in the crontab file on the remote server. However, the file upload and writing the cron entry need to occur within a bash shell script so that I only need to execute the script on my local machine and the script is copied to the remote host and the cron entry is written to the crontab.

Is there a way that I can use an ssh command, within the script, that logs me into the remote server, opens the crontab file and writes the cron entry.

Any help is very welcome

like image 270
Wettstein Roland Avatar asked Feb 26 '23 01:02

Wettstein Roland


1 Answers

I would:

  1. extract the user's crontab with crontab -l > somefile
  2. modify that file with the desired job
  3. import the new crontab with crontab somefile
like image 105
glenn jackman Avatar answered Mar 26 '23 02:03

glenn jackman