⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch48_04.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
></DT><DDCLASS="listitem"><PCLASS="para">This matches whatever comes before the date.Match at the beginning of a line (<CODECLASS="literal">^</CODE>) or (<CODECLASS="literal">|</CODE>) matcha space, TAB, opening parenthesis, comma, or semicolon(<CODECLASS="literal">[<IMGSRC="../chars/squ.gif"ALT=" ">T(,;]</CODE>).This keeps <EMCLASS="emphasis">egrep</EM> from matching other words that start with orcontain the month abbreviation <CODECLASS="literal">[Dd]ec</CODE>.</P></DD><DTCLASS="term"><CODECLASS="literal">((([Dd]ec[^<IMGSRC="../chars/squ.gif"ALT=" ">T]*|\*)[<IMGSRC="../chars/squ.gif"ALT=" ">T]*|(012|12|\*)/)0*8)</CODE></DT><DDCLASS="listitem"><PCLASS="para">This matches the date.Match <EMCLASS="emphasis">Dec</EM> or <EMCLASS="emphasis">dec</EM> with zero or more of any character besidesspace or TAB afterthat (<CODECLASS="literal">[Dd]ec[^<IMGSRC="../chars/squ.gif"ALT=" ">T]*</CODE>)-or (<CODECLASS="literal">|</CODE>) have a literal asterisk(<CODECLASS="literal">\*</CODE>), which means &quot;match this on any month of the year.&quot;Or (<CODECLASS="literal">|</CODE>) match a numeric month like <EMCLASS="emphasis">012</EM> or <EMCLASS="emphasis">12</EM> or a literalasterisk (<CODECLASS="literal">(012|12|\*)</CODE>)-followed by a slash (<CODECLASS="literal">/</CODE>).Finally, you need today's date: it starts with any number ofzeros and ends with <EMCLASS="emphasis">8</EM> (<CODECLASS="literal">)0*8)</CODE>).</P></DD><DTCLASS="term"><CODECLASS="literal">([^0123456789]|$)</CODE></DT><DDCLASS="listitem"><PCLASS="para">The end of the expression matches lines anything except adigit&nbsp;- or matches the end of the line.This keeps <EMCLASS="emphasis">egrep</EM> from matching non-dates like <EMCLASS="emphasis">8.75</EM>.</P></DD></DL><PCLASS="para">Whew.That expression is repeated for every other day that needs to be matched.On Fridays, the output of <EMCLASS="emphasis">/usr/lib/calendar</EM> has four lines&nbsp;- oneeach for Friday, Saturday, Sunday, and Monday.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-3180-SECT-1.3">48.4.3 Automating Your Own Calendar </A></H3><PCLASS="para">If you want a calendar every weekday, put a line like the following intoyour<SPANCLASS="link">personal <EMCLASS="emphasis">crontab</EM> file (<ACLASS="linkend"HREF="ch40_12.htm"TITLE="Periodic Program Execution: The cron Facility ">40.12</A>)</SPAN>.We've split this onto two lines for printing, but you should type it allon one line:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch06_03.htm"TITLE="6.3 Predefined Environment Variables ">$USER</A> <ACLASS="co"HREF="ch44_09.htm"TITLE="44.9 Testing Your Success ">&amp;&amp;</A> <ACLASS="co"HREF="ch13_01.htm"TITLE="13.1 Using Standard Input and Output">&lt;</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen"><ACLASS="indexterm"NAME="AUTOID-57831"></A><ACLASS="indexterm"NAME="AUTOID-57834"></A><ACLASS="indexterm"NAME="AUTOID-57837"></A>6 6 * * 1-5 tf=/tmp/cal.$USER; umask 077; /bin/calendar &gt; $tf;    test -s $tf &amp;&amp; mail -s 'Calendar for today' $USER &lt; $tf; rm -f $tf</PRE></TD></TR></TABLE></P><PCLASS="para">That runs <EMCLASS="emphasis">calendar</EM> from my home directory at<SPANCLASS="link">6:06 a.m. (<ACLASS="linkend"HREF="ch40_05.htm"TITLE="Avoiding Other at and cron Jobs ">40.5</A>)</SPAN>every weekday morning.It sets a<SPANCLASS="link">Bourne shell variable (<ACLASS="linkend"HREF="ch06_08.htm"TITLE="Shell Variables ">6.8</A>)</SPAN>named <EMCLASS="emphasis">tf</EM> with the name of a temporary file in the<SPANCLASS="link"><EMCLASS="emphasis">/tmp</EM> directory (<ACLASS="linkend"HREF="ch21_03.htm"TITLE="Unique Names for Temporary Files ">21.3</A>)</SPAN>,and sets a<SPANCLASS="link"><EMCLASS="emphasis">umask</EM> (<ACLASS="linkend"HREF="ch22_04.htm"TITLE="Setting an Exact umask ">22.4</A>)</SPAN>to make the file private.Then it runs <EMCLASS="emphasis">calendar</EM> and saves the output in the temporary file.If there's a calendar for today, the <EMCLASS="emphasis">mail</EM> command sends the fileto me.(The <EMCLASS="emphasis">-s</EM> option on our <EMCLASS="emphasis">mail</EM> command adds the <CODECLASS="literal">Subject:</CODE>line <EMCLASS="emphasis">Calendar for today</EM> to the message.It isn't required.)Finally, the temporary file is removed.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-57859"></A><ACLASS="indexterm"NAME="AUTOID-57862"></A><ACLASS="indexterm"NAME="AUTOID-57865"></A>If you don't have personal <EMCLASS="emphasis">crontab</EM>s, you can use a<SPANCLASS="link">self-restarting <EMCLASS="emphasis">at</EM> job (<ACLASS="linkend"HREF="ch40_08.htm"TITLE="Automatically Restarting at Jobs ">40.8</A>)</SPAN>and the<SPANCLASS="link"><EMCLASS="emphasis">nextweekday</EM> script (<ACLASS="linkend"HREF="ch40_10.htm"TITLE="nextday, nextweekday: Tomorrow or Next Weekday ">40.10</A>)</SPAN>instead.<ACLASS="indexterm"NAME="AUTOID-57873"></A></P></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch48_03.htm"TITLE="48.3 A Scratchpad on Your Screen "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 48.3 A Scratchpad on Your Screen "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch48_05.htm"TITLE="48.5 leave: A Maddening Aid to Quitting on Time "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 48.5 leave: A Maddening Aid to Quitting on Time "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">48.3 A Scratchpad on Your Screen </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">48.5 leave: A Maddening Aid to Quitting on Time </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -