Skip to content

Instantly share code, notes, and snippets.

View DavidSzczesniak's full-sized avatar

David Szczesniak DavidSzczesniak

View GitHub Profile
By default, everyone is allowed to create cron and at jobs.
However, users can be denied if explicitly listed in one of the .deny files: at.deny or cron.deny.
These are both located in /etc by default.
@DavidSzczesniak
DavidSzczesniak / at_batch.txt
Last active May 17, 2018 15:52
These are one time jobs that aren't set to repeat like crons
\!h at format
in the command line type:
at <time> <date> e.g noon tomorrow or 11am june 26
this opens an at> prompt. Type in commands to be executed.
CTRL+D to end job definition - the new job is now set
atq - to list jobs
@DavidSzczesniak
DavidSzczesniak / system_crons.txt
Last active May 17, 2018 16:01
This is a good example of the format in which a system cron job is written.
crontab -e
5 20 * * 1-5 root /usr/sbin/backup.sh
\!h Seven fields:
- Minute (0-59): 5 past the hour
- Hour (0-23): 8pm
- Day of the Month (0-31): any day
- Month (1-12): any month
- Day of the Week (0-7): Mon-Friday
@DavidSzczesniak
DavidSzczesniak / match_variables.pl
Last active April 10, 2018 14:14
These are how strings are stored when processed by a pattern.
# The part of the string that matches the pattern is automatically stored in $&
if ("Hello there, neighbor" =~ /\s(\w+),/) {
print "That actually matched '$&'.\n";
}
# In the above example, the part that matched was " there," (a space, a word, and a comma).
# In comparison, capture $1 would have just the five-letter word.
# Whereas, $& has the entire matched section.
@DavidSzczesniak
DavidSzczesniak / noncap_parentheses.pl
Last active April 10, 2018 11:34
Provides a way to use parentheses to grop things without triggering the capture groups.
# Example:
# Before - bronto is $1 and what we want is $2. This will get confusing in more complicated patterns
if ((/bronto)?saurus (steak|burger)/) {
print "Fred wants $2\n";
}
# After - now using noncapturing parentheses around bronto
if (/(?:bronto)?saurus (steak|burger)/) {
print "Fred wants $1\n";
@DavidSzczesniak
DavidSzczesniak / named_captures.pl
Last active April 10, 2018 12:02
Allows you to capture parts of a string with parentheses and then look in the number variables $1, $2 etc. to get back the parts of the string matched.
if (/bronto)?saurus (steak|burger)/ {
print "Antisa wants a $2\n";
}
# Even if bronto is not there, its part of pattern that goes into $1.
# You can refer back to a labeled group using \g{label}:
my $names = 'Fred Flintstone and Wilma Flintstone';
if ($names =~ m/(?<last_name>\w+) and \w+ \g{last_name}/) {
@DavidSzczesniak
DavidSzczesniak / char_interpret.pl
Last active April 9, 2018 16:49
These are modifiers allow you to tell Perl how to interpret the characters in a match.
# /a - use the ASCII interpretation
# /u - use the Unicode interpretation
# /l - respect the locale
# A single /a modifier affects the character class shortcuts,
# but having two /a modifiers also tells Perl to use ACII-only case-folding.
\!h # Some examples:
@DavidSzczesniak
DavidSzczesniak / x_modifier.txt
Last active April 9, 2018 14:48
This modifer makes the whitespace inside a pattern insignificant. Very useful for spacing out your regexes, making them more readable.
\!h # Example, allows for code spacing:
/-?[0-9]+\.?[0-9]/ # - without
/ -? [0-9] + [0-9]* /x # - with
@DavidSzczesniak
DavidSzczesniak / unicode_props.pl
Last active April 6, 2018 16:53
Instead of matching on a particular character, you can match a type of character. Each character has a property, they can all be found in the perluniprops documentation.
\!h # To match a particular property, you put the name in \p{PROPERTY}
# Example - to match any sort of space, use the 'Space' property:
if (/\p{Space}/) {
print "The string has some whitespace.\n";
}
# The above is slightly more expansive than \s as it matches more properties, like NEXT LINE or LINE TABULATION (vertical line).
@DavidSzczesniak
DavidSzczesniak / char_class_shortcuts.pl
Last active April 9, 2018 13:37
Sets of characters that can match a single location in the pattern of a regular expression. The pattern has to match any ONE of the characters in the brackets.
\!h # Some basic shortcuts:
# \s meaning any whitespace
$_ = "fred \t \t barney";
if (/fred\s+barney/) {
print "It matched!\n"
}
# \h can be used for horizontal whitespace only