Hacker Public Radio

HPR3423: "upg.sh" my "dump.txt" to "note.md"


Listen Later

upg.sh my dump.txt to note.md
SYNOPSIS: upg.sh
Upgrade your system and store stdout into a markdown file.
#!/bin/bash
# upg.sh
FILENAME=sys-upgrade$(date +%m-%d-%Y).md
DIRECTORY="${HOME}/Documents/"
# step 1: formatting.
echo -e "# **System Upgrade:** $(date)n"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "**Command:** `sudo apt-get update; sudo apt-get upgrade --yes`n"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "**Command Breakdown:**"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "- `sudo`, Admin Privilages."
| tee -a ${DIRECTORY}${FILENAME}
echo -e "- `apt-get`, Package Manager."
| tee -a ${DIRECTORY}${FILENAME}
echo -e "- `update;`, Package Manager's task; update the system software repositories."
| tee -a ${DIRECTORY}${FILENAME}
echo -e "- `sudo apt-get upgrade`, Perform system upgrade with updated repositories."
| tee -a ${DIRECTORY}${FILENAME}
echo -e "- `--yes`, Answers yes to the prompt."
| tee -a ${DIRECTORY}${FILENAME}
# step 2: run commands with formatting.
echo -e "n**Command std-output:**n"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "```"
| tee -a ${DIRECTORY}${FILENAME}
echo $(date)
| tee -a ${DIRECTORY}${FILENAME}
sudo apt-get update
| tee -a ${DIRECTORY}${FILENAME}
echo -e "n# System update completed.n"
| tee -a ${DIRECTORY}${FILENAME}
sudo apt-get upgrade --yes
| tee -a ${DIRECTORY}${FILENAME}
echo -e "n# System upgrade completed.n"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "```n"
| tee -a ${DIRECTORY}${FILENAME}
# step 3: additional details with more formatting.
echo -e "**Upgraded Package Details:**n"
| tee -a ${DIRECTORY}${FILENAME}
echo -e "```"
| tee -a ${DIRECTORY}${FILENAME}
PKGLIST=$(sed -n "/The following packages will be upgraded:/,/^.. upgraded/p" ${FILENAME}
| sed '1d;$d' | xargs -n 1 | sed '/:i386$/d')
PKGCACHE=$(echo -e "${PKGLIST}n"
| xargs -n1 -I _ apt-cache search _)
echo "${PKGCACHE}" > ${DIRECTORY}delete.txt
echo "${PKGLIST}"
| xargs -n 1 -I _ echo "sed -n '/^_ /p'" "${DIRECTORY}delete.txt"
| bash | tee -a ${DIRECTORY}${FILENAME};
echo -e "```"
| tee -a ${DIRECTORY}${FILENAME}
rm -v ${DIRECTORY}delete.txt;
PKGLIST=
PKGCACHE=
# step 4: place EOF (end of file).
sed -i '/EOF/d' ${DIRECTORY}${FILENAME}
echo "EOF" >> ${DIRECTORY}${FILENAME}
#EOF
Script breakdown: upg.sh
First, we declare bash as our shell with #!/bin/bash. We could also use #!/bin/sh for a more portable script.
I like to paste the name of the script we're working on into the script itself # upg.sh.
Setup a couple of variables to shorten the syntax.
FILENAME=sys-upgrade$(date +%m-%d-%Y).md
DIRECTORY="${HOME}/Documents/"
# step 1: formatting.
Build labels and a short breakdown of the update/upgrade commands used.
echo -e "# **System Upgrade:** $(date)n" <-- formatting: label with date.
| tee -a ${DIRECTORY}${FILENAME} <-- path/to/file
echo -e "**Command:** `sudo apt-get update; sudo apt-get upgrade --yes`n" <-- formatting: command label.
| tee -a ${DIRECTORY}${FILENAME}
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

290 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

372 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

651 Listeners

Curious Cases by BBC Radio 4

Curious Cases

822 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

423 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,061 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

179 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,797 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

228 Listeners