CS 279 - Week 14 Lecture 2 - 2022-11-30 TODAY WE WILL * announcements * quick Bash case additional note * a quick word on df and du * some fun utilities, part 1 * intro to at/batch/crontab * [if time] some fun utilities, part 2 * prep for next class * Should be working on Homework 9 * Please try to login to vlinux.humboldt.edu and e-mail me if you can or if you cannot ===== Bash shell case statement - quick addition ===== * you can put | between case patterns to let them "share" a case MOO | Moo | mOO) echo "this worked! handles MOO or Moo or mOO" ;; (and this will be included in W14-1's case-play example ===== two more "about the system" commands ===== * df - reports disk free space du - reports disk space in use by a given file or directory * du ~/bin # disk space used by your bin directory ==== date ==== * gives the current date and time * can give it format descriptors to specify what parts of this get included -- start descriptor with + and start each format descriptor within with % +%m - month as a number +%a - day of the week as three-letter abbreviation +%A - full written-out week day +%B - full month +%b - month as a 3-letter abbrev +%D - numerical date MM/DD/YY ...etc.! ...and a quoted string is fine for this descriptor; date '+Month: %B' ===== cal ===== * displays ASCII version of a monthly calendar * specify a year? get all 12 months cal 1994 specify a month (as a number), then a year - get THAT month in that year cal 7 1776 ===== sleep ===== * do nothing for a specified number of seconds (approximately) sleep 5 ===== time ===== * START a command with this and it outputs the real time, user time, and system time it took to run that command time beeper.sh 5 ===== wait ===== * wait until the specified process id completes to go on wait 4604 # where 4604 is a process id wait %1 # where 1 is a job number note: semicolon can be put between 2 shell commands to run as one unit wait %3; echo "hi" ===== nice, renice ===== * because jobs DO have priorities...! * nice lets you ask for a lower priority for a process than it normally would get; typically used with a process being run in the background! nice [-n num] <cmd> ^ typically between 1 and 19, where 19 is *lowest* priority nice -n 19 big-honking-task.sh & * renice lets you try to lower the priority of a running process renice [-n num] [-p <process-d>] ==== at, batch, crontab - running a thing later and/or regularly ==== * when you want to ask for a task to be run once at a specified time (at lets you do this!) or once when the load on the system is low enough (batch lets you do this!) or regularly at a specified date and/or time etc. (crontab lets you do this!) * course text! 2021 update "Linux Fundamentals": Chapter 58 - Scheduling! ----- at ----- * you specify when it should be done at 9:30am at 4:15pm * then you get at> prompts, where you can type the desired commands to be done * (and type ^d when you are done entering commands) * can also see a list of what's pending, you can remove jobs, and more (see the man page) at -l # list the jobs in at's queue atrm 1 # remove the first job in at's queue, etc. * NOTE: type ^d when you are done entering commands for an at job!!! ----- batch ----- * usually intended for long, low-priority jobs * can list and remove jobs created with batch using the command * NOTE: type ^d when you are done entering commands for a batch job!!! ===== cron and crontab ===== * cron - a time-based job-scheduler in UNIX-like operating system a daemon! (an always-running special process, I believe) "Linux Fundamentals" claim: the most used program on Debian Linux (!!) * crontab - stands for cron table -- a configuration file that specifies commands to be run periodically at fixed times, dates, or intervals if permitted, each user can have their own crontab (accessed and edited via the crontab command) * SO: you can request a periodic job be inserting crontab entries into a crontab file! * crontab -r - to REMOVE your crontab file * to create/edit your crontab file: crontab -e you can set the EDITOR environment command to CHANGE crontab's default editor from vi -- remember to export that! export EDITOR=/usr/bin/nano * crontab file - contains crontab entries comment lines: either have # in COLUMN 1, or are ALL BLANK specification of a job to be scheduled: * field 1 - minute it is to be run (0-59) * field 2 - hour it is to be run (0-23) * field 3 - day of the month (1-31) * field 4 - month of the year (1-12) * field 5 - day of the week (0-6, where 0 is Sunday) * command to execute - need FULL pathnames here, in general! * you separate the fields with a blank * IF you put an * in any of the fields 1-5, it represents ALL valid values * * * * * /bin/date >> /home/st10 ..runs date command every minute...! * comma-separated list: do for all those values in field 3: 1,11,15 * ... # execute on 1st, 11th, and 15th of the month * range separated by a dash 1-5 #means 1, 2, 3, 4, 5