英文:
How to run a bash script source from another bash script and invoke the corresponding functions. via crontab
问题
- 打开终端后,我输入了这个命令:
moabdelaziz@pop-os:~$ crontab -r
- 并且安排了这个任务:
* * * * * /bin/bash /home/moabdelaziz/Backups/backup.sh >> /home/moabdelaziz/output.txt
- backup.sh
#!/bin/bash
TargetDir=/home/mohamed/Date
TargetBackup=/home/mohamed/Backup
EncryptionKey="PASS"
days=12
source ../backup_restore_lib.sh
validate_backup_params ${TargetDir} ${TargetBackup} ${EncryptionKey} ${days}
backup ${TargetDir} ${TargetBackup}
- backup_restore_lib.sh 包含以下函数:
validate_backup_params {...}
Encryption {...}
Decryption {...}
remote_server {...}
backup {...}
validate_restore_params {...}
restore {...}
很遗憾,它不起作用 :(. 有人可以指出我做错了什么吗?提前感谢!
英文:
- After I opened the terminal, I typed this command:
moabdelaziz@pop-os:\~$ crontab -r
- And scheduled the task:
* * * * * /bin/bash /home/moabdelaziz/Backups/backup.sh >> /home/moabdelaziz/output.txt
- backup.sh
#!/bin/bash
TargetDir=/home/mohamed/Date
TargetBackup=/home/mohamed/Backup
EncryptionKey="PASS"
days=12
source ../backup_restore_lib.sh
validate_backup_params ${TargetDir} ${TargetBackup} ${EncryptionKey} ${days}
backup ${TargetDir} ${TargetBackup}
- backup_restore_lib.sh contains those functions
validate_backup_params {...}
Encryption {...}
Decryption {...}
remote_server {...}
backup {...}
validate_restore_params {...}
restore {...}
Unfortunately, it does not work :(.
Can anyone point me to anything I'm doing wrong? Thanks in advance!
答案1
得分: 1
一般来说,cron定时任务脚本在用户的主目录中执行。这意味着你的
source ../backup_restore_lib.sh
将会寻找一个名为/home/backup_restore_lib.sh
的文件来进行源代码引用。
最好提供要引用的文件的绝对路径。
英文:
In general, crontab scripts are executed in the home directory of the user. That means that your
source ../backup_restore_lib.sh
will look for a file /home/backup_restore_lib.sh
to source.
It is better to put in the absolute path to the file that you want to source.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论