开发者

how to auto setup a "AT" schedule job once after reboot

开发者 https://www.devze.com 2023-02-15 00:09 出处:网络
when I loging incentos as root via ssh i type at-f /etc/at_stopssh.txt now + 5 minutes and it works, one schedule job has been setup sucessfully

when I loging in centos as root via ssh i type

at  -f /etc/at_stopssh.txt now + 5 minutes

and it works, one schedule job has been setup sucessfully

at_stopssh.txt include a simple command shows below

service sshd stop

then i try to automate it after rebooting by adding it into rc.local file. so i add a new line in the rc.local

at  -f /etc/at_stopssh.txt now + 5 minutes

after reboot . i checked by atq command, it seems there is no job schedule has been added.

I try it in another way. i added another newline into rc.local file shows below

echo "/sbin/service/service /usr/sbin/ssh开发者_开发技巧d/sshd stop"|/usr/bin/at now + 5 minutes

and it was non funcational at all again.

for your reference it is my env file content shows below

env | sort > /tmp/env.at



_=/bin/env
G_BROKEN_FILENAMES=1
HISTSIZE=1000
HOME=/root
HOSTNAME=377pc.cn
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
LESSOPEN=|/usr/bin/lesspipe.sh %s
LOGNAME=root
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
SHELL=/bin/bash
SHLVL=1
SSH_CLIENT=121.228.206.52 31795 22
SSH_CONNECTION=121.228.206.52 31795 205.185.124.26 22
SSH_TTY=/dev/pts/0
TERM=xterm
USER=root

My question is what is wrong with it? how could i aotomatically setting up a new "AT" job and make it functional after a reboot?

Many thanks Austin


At-jobs are cleared upon restart; they’re not appropriate for cron jobs that should occur after restart.

Luckily enough, there is a special @reboot crontab entry that lets you run a job after reboot. If you need to wait 5 minutes, you can insert an appropriate sleep.

However, if what you're really trying to do is prevent the SSH server from being started in the first place, you should chkconfig the service off. I'm not 100% sure what the name is on CentOS, but on Ubuntu it would be chkconfig ssh off.

0

精彩评论

暂无评论...
验证码 换一张
取 消