quickreference:unix
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
quickreference:unix [2023/10/08 18:26] – rodolico | quickreference:unix [2025/02/05 00:12] (current) – [Shell (mainly BASH)] rodolico | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Systems Administration ===== | ===== Systems Administration ===== | ||
+ | ==== Partitioning large drives ==== | ||
+ | |||
+ | Drives greater than 2 Terabytes are not handled well by the standard //fdisk// application, | ||
+ | |||
+ | This assumes we have a drive, sdg, that we want to set up with gpt and create one partition on. That partition will set up on optimal sector boundries, and use all of the space available. | ||
+ | |||
+ | <code bash> | ||
+ | # remove all old file system information. Not necessary, but I do it just because I can | ||
+ | wipefs -a /dev/sdg | ||
+ | # make this a gpt disk. Will wipe out any other partitioning scheme | ||
+ | parted /dev/sdg mklabel gpt | ||
+ | # make a new partition on optimal sector boundries. This is a primary partition, and starts | ||
+ | # at the beginning of the disk (0%) and goes to the end of the disk (100%) | ||
+ | # I put that in quotes as, from what I've read, the percent symbol does not work well | ||
+ | # within the bash command line | ||
+ | # note, we are not telling it what file system to use, so it defaults to Linux | ||
+ | parted -a optimal /dev/sdg mkpart primary ' | ||
+ | # display the information on the disk | ||
+ | parted /dev/sdg print | ||
+ | # format as ext4, no reserved space, and a disk label marked ' | ||
+ | mkfs.ext4 -m0 -Lbackup /dev/sdg | ||
+ | |||
+ | </ | ||
==== Rapidly wipe multiple hard drives ==== | ==== Rapidly wipe multiple hard drives ==== | ||
Line 48: | Line 71: | ||
</ | </ | ||
- | ==== Check SSL Cert Expiration Date ==== | ||
- | |||
- | Ever wondered when your SMTP SSL Certificates are up for renewal? A quick and dirty way of doing it from the command line was shown at [https:// | ||
- | |||
- | Note: the discussion covered other things, and is well worth a 5 minute read. | ||
- | |||
- | <code bash> | ||
- | printf ' | ||
- | openssl s_client -connect smtp.example.com: | ||
- | openssl x509 -dates -noout | ||
- | </ | ||
- | |||
- | This basically makes a connection to smtp.example.com on port 25, issuing a starttls, then sends the //quit// command which logs out. The openssl command retrieves the certificate (second line), then passes that to another instance of openssl which decodes it to get the dates from it. You can also test port 587 (submission) by changing the 25 to a 587/ | ||
- | |||
- | You can also test an IMAP server. IMAP uses the command //a1 logout// to exit, and port 993 for an SSL connection, so your script becomes: | ||
- | <code bash> | ||
- | printf 'a1 logout\n' | ||
- | openssl s_client -connect mail.example.com: | ||
- | openssl x509 -dates -noout | ||
- | </ | ||
- | |||
- | **Note:** since we are going in over a non-SSL enabled port, we must do the starttls command. However, by removing the -starttls protocol part, we can go directly to the SSL port (465 for smtps and 993 for imaps). To check smtps, our command becomes: | ||
- | |||
- | <code bash> | ||
- | printf ' | ||
- | openssl s_client -connect smtp.example.com: | ||
- | openssl x509 -dates -noout | ||
- | </ | ||
- | |||
- | I //think// that is the correct description of what is happening, but not sure. However, it works. | ||
==== Rename Server ==== | ==== Rename Server ==== | ||
Line 91: | Line 84: | ||
<code bash> | <code bash> | ||
# change the host name, and the postfix name if that is installed | # change the host name, and the postfix name if that is installed | ||
- | sed -i.old ' | + | sed -i.old ' |
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
/ | / | ||
# update the aliases, if they exist | # update the aliases, if they exist | ||
Line 238: | Line 237: | ||
===== Shell (mainly BASH) ===== | ===== Shell (mainly BASH) ===== | ||
+ | ==== Here Documents ==== | ||
+ | |||
+ | Most unix users are familiar with echo' | ||
+ | |||
+ | A **here document** is a way of having multiple lines processed at one time. In many cases, you can have similar functionality using quotes, but here documents are more robust. | ||
+ | |||
+ | For example, a simple test of a newly built mail system might include creating a file with all of the headers necessary, then passing that to // | ||
+ | |||
+ | <code bash> | ||
+ | sendmail user@example.com << EOF | ||
+ | To: user@example.com | ||
+ | from: root@example.org | ||
+ | Subject: test | ||
+ | |||
+ | This is a test | ||
+ | EOF | ||
+ | </ | ||
+ | |||
+ | The entire block above is one command. Here is the breakdown. | ||
+ | |||
+ | - //sendmail user@example.com// | ||
+ | - //<<// | ||
+ | - //EOF// is the tag which will mark the end of the text for the here document | ||
+ | - Everything up to the EOF is the actual string to be passed to sendmail | ||
+ | - //EOF// at the end marks the end of the here document. **Note**: there must be no leading or trailing whitespace. The tag must be exactly as entered after the << (case sensitive), and must be the only thing on the final line. | ||
+ | |||
+ | This only touches the surface of here documents. See [[https:// | ||
==== Find files within date range containing text ==== | ==== Find files within date range containing text ==== | ||
quickreference/unix.1696807587.txt.gz · Last modified: 2023/10/08 18:26 by rodolico