当前位置: 技术问答>linux和unix
shell中修改文件的内容,请高手来指教
来源: 互联网 发布时间:2016-11-23
本文导语: 要求写一个shell,往/etc/crontab文件中加入一个定时任务: * */1 * * * root /usr/sharescm/timingshutdown.sh 判断如果/etc/crontab中有改记录这一行,然后再重新写入 请问听懂了没? 我使用sed命令:sed -e '/timingshutdown.sh/d' ...
要求写一个shell,往/etc/crontab文件中加入一个定时任务:
* */1 * * * root /usr/sharescm/timingshutdown.sh
判断如果/etc/crontab中有改记录这一行,然后再重新写入
请问听懂了没?
我使用sed命令:sed -e '/timingshutdown.sh/d' /etc/crontab
输出内容:# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
00 04 * * * root /usr/sharescm/backupdb.sh
#*/5 * * * * root /usr/sharescm/fileshow.sh
但是vi查看/etc/crontab:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
00 04 * * * root /usr/sharescm/backupdb.sh
#*/5 * * * * root /usr/sharescm/fileshow.sh
[color=#FF0000]* */1 * * * root /usr/sharescm/timingshutdown.sh[/color]
这段内容还存在,请各位大虾指教如何完成这个shell
* */1 * * * root /usr/sharescm/timingshutdown.sh
判断如果/etc/crontab中有改记录这一行,然后再重新写入
请问听懂了没?
我使用sed命令:sed -e '/timingshutdown.sh/d' /etc/crontab
输出内容:# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
00 04 * * * root /usr/sharescm/backupdb.sh
#*/5 * * * * root /usr/sharescm/fileshow.sh
但是vi查看/etc/crontab:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
00 04 * * * root /usr/sharescm/backupdb.sh
#*/5 * * * * root /usr/sharescm/fileshow.sh
[color=#FF0000]* */1 * * * root /usr/sharescm/timingshutdown.sh[/color]
这段内容还存在,请各位大虾指教如何完成这个shell
|
我使用sed命令:sed -e '/timingshutdown.sh/d' /etc/crontab
换成
sed -i -e '/timingshutdown.sh/d' /etc/crontab
换成
sed -i -e '/timingshutdown.sh/d' /etc/crontab