2017-07-14

Scheduling a user's job using command 'at'

I just thought of creating a schedule job using the Linux command 'at'.  Here's what I did.

$ at -t 1707141900
at> sudo yum install kernel-2.6.32-642.13.2.el6 kernel-devel-2.6.32-642.13.2.el6 kernel-headers-2.6.32-642.13.2.el6 kernel-firmware-2.6.32-642.13.2.el6 redhat-release-server-6Server-6.8*.el6 -y
at> sudo yum -x kernel*,redhat-release* update -y --nogpgcheck
at> sudo reboot
at> <EOT>
job 2 at 2017-07-14 19:00

$ atq
2       2017-07-14 19:00 a mmond

There have been some instances that you want to run the job on a different schedule, so it's in man pages and lots of examples from the web. But below are the ones I used which are pretty much straight-forward.

at 7 pm Tuesday
at now +5 minutes

Now I played around and see if I can patch the test server and reboot it afterwards.  And to display the content of my job id #2, I use "at -c 2".

$ at -c 2
#!/bin/sh
# atrun uid=8811 gid=804
# mail mmond 0
umask 22
HOSTNAME=dksvrlog01.a.globalhosting.net; export HOSTNAME
SHELL=/usr/bin/ksh; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=10.16.120.18\ 11986\ 22; export SSH_CLIENT
QTDIR=/usr/lib64/qt-3.3; export QTDIR
QTINC=/usr/lib64/qt-3.3/include; export QTINC
SSH_TTY=/dev/pts/1; export SSH_TTY
USER=mmond; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
A__z=\"\*SHLVL; export A__z
PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin; export PATH
MAIL=/var/spool/mail/mmond; export MAIL
PWD=/home/mmond; export PWD
LANG=en_US.UTF-8; export LANG
MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles; export MODULEPATH
LOADEDMODULES=; export LOADEDMODULES
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=2; export SHLVL
HOME=/home/mmond; export HOME
LOGNAME=mmond; export LOGNAME
QTLIB=/usr/lib64/qt-3.3/lib; export QTLIB
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=10.16.120.18\ 11986\ 10.225.34.32\ 22; export SSH_CONNECTION
MODULESHOME=/usr/share/Modules; export MODULESHOME
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
cd /home/mmond || {
         echo 'Execution directory inaccessible' >&2
         exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER48cb17a0'
sudo yum install kernel-2.6.32-642.13.2.el6 kernel-devel-2.6.32-642.13.2.el6 kernel-headers-2.6.32-642.13.2.el6 kernel-firmware-2.6.32-642.13.2.el6 redhat-release-server-6Server-6.8*.el6 -y
sudo yum -x kernel*,redhat-release* update -y --nogpgcheck
sudo reboot
marcinDELIMITER48cb17a0


And I received a mail stating each commands executed.  Awesome!

No comments:

Post a Comment