There is a crash CT script to remotely restart the processes on the target server. Everything is OK when it is executed separately under shell, but it cannot be executed when it is added to the cron task. Some code is as follows:
Secondary CT Script: (/data/home/restart_secondary CT)
#! /Usr/bin/CT
Spawn ssh-p xxx root@xxx.xxx.xxx.xxx
# Keep CT "* Root's password *"
Secondary CT "* Tencent :*"
Send "Sh some remote scripts"
Send "Exit/N"
Ct eof exit 0
Crontab task:
*/5 */data/monitor/new_itil_dicts/syn_tcms_data/run_syn.php/tmp/test. log 2>/dev/null
There is no problem in executing everything in shell alone, but it cannot be put into cron. Start to locate the problem. The entire process is as follows:
1. First, the task of modifying crontab is incorrectly output to an execution file.
*/5 */data/monitor/new_itil_dicts/syn_tcms_data/run_syn.php/tmp/test. log 2> & 1
2. view the error output in the/tmp/test. log file. The prompt is as follows:
I cannot find the command SSH, which makes me a bit confused. Why can't I find the SSH command (I installed it in the/usr/local/bin directory, the echo $ path/usr/local/bin directory is clearly in the path. At this time, it is assumed that the environment variables used by cron are different from those used by shell, So Google, it is found that cron contains the following content in/etc/crontab:
Shell =/bin/sh
Path =/usr/bin:/usr/sbin:/bin:/usr/lib/news/bin
Mailto = root
#
# Check scripts in cron. Hourly, cron. daily, cron. weekly, and cron. Monthly
#
Note that the PATH variable here finds that the SSH installation directory is not above this. Here we will know the problem caused by the use of different path variables in cron and shell. So the solution can be:
1. Modify the PATH variable of/etc/crontab to include commands used in audit CT, such as SSH
Shell =/bin/sh
Path =/usr/bin:/usr/sbin:/bin:/usr/lib/news/bin:/usr/local/bin
Mailto = root
2. the full path of the command used by the keep CT script is as follows,
#! /Usr/bin/CT
Spawn/usr/local/bin/ssh-p xxx root@xxx.xxx.xxx.xxx
# Keep CT "* Root's password *"
Secondary CT "* Tencent :*"
Send "Sh some remote scripts"
Send "Exit/N"
Ct eof exit 0