Search code examples
linuxbashcronbackup

Cron in bash (linux)


I need to add this script to cron. For example, make a backup every week. But I don't know how to pass values. The script doesn`t have any arguments, bat values read from the console. Can you help me, please?

#!/bin/bash
read -p "Write what you want or -h to know how script works:  " command
if [ $command = "backup" ]
then
    IFS="~"
    read -p "Write  extensions of file to backup:   " exts
...
    ```

Solution

  • Write a driver script that provides input to the script via a here-document.

    #!/bin/bash
    
    /path/to/backup_script <<EOF
    backup
    ext1~ext2~ext3
    EOF
    

    Then put this driver script in crontab.