If you use ssh-agent and have scripts that use commands, such as ssh or scp, that need your ssh key, you may have had the experience of running your script only to discover that you never ran ssh-add to add your key to ssh-agent. So, you type the passphrase once to run the script, and then you have to run ssh-add afterward and type it again to add it to ssh-agent.
To avoid this, add a check to the top of your script to see whether your key is loaded. If not, load it, and avoid having to run ssh-add afterward:
if ! ssh-add -L | grep --silent '/\.ssh/id_.sa'; then ssh-add fi
The -L option of ssh-add shows what keys are added, its output is piped to grep to check to see whether your key is loaded. If it's not, ssh-add is invoked to add your key.
If you want to extract images from a PDF file, you can use the pdfimages program from the poppler package. To extract the images from an entire file, run the command:
pdfimages input.pdf image-root
If you want to extract images from a range of pages, you can use the -f and -l options to specify the first and last pages in the range. To extract the images from pages two to four, use the command:
pdfimages -f 2 -l 4 input.pdf image-root
Images are written to files named image-root-nnn.xxx, where nnn is an image number and xxx is the image type (for example, jpg).
If you have scripts that need to be run as root, you can check for this at the start of the script with:
if [[ $UID -ne 0 ]]; then echo "Must be run as root" exit 1 fi
If you use sudo, you even could restart the script with sudo if it was not run as root:
if [[ $UID -ne 0 ]]; then sudo -p "Restarting with sudo. Password: " sh $0 $* stat=$? exit $stat fi
The sudo command runs the script as sh $0 $*. The sh is included in case the script does not have the execute bit set.
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
|The Many Paths to a Solution||Sep 21, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Android Browser Security--What You Haven't Been Told
- Readers' Choice Awards 2013
- Epiq Solutions' Sidekiq M.2
- Downloading an Entire Web Site with wget
- The Many Paths to a Solution
- Securing the Programmer
- Nativ Disc
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide