You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials Show Sample Output
I always wanted to be able to copy formatted HTML, like from emails, on trello cards or READMEs... but the formatting is always wrong... But from this two links: * https://jeremywsherman.com/blog/2012/02/08/pasting-html-into-markdown/ * http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard For instance, to to copy an formatted email to a trello card, just: 1. Select the email body 2. run: xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github - | xclip -i -t text/plain 3. Paste in your trello card 4. Profit! 8-)
It requires https://jqplay.org/, that comes with brew: brew install jq Show Sample Output
Will check if the given module is installed in the @INC. It will print the path and return 0 if found, or 1 otherwise. Based on script from SharpyWarpy in http://www.linuxquestions.org/questions/linux-general-1/how-to-list-all-installed-perl-modules-216603/ Show Sample Output
Got the idea from there http://fixunix.com/questions/15902-bash-checking-if-env-var-set.html Show Sample Output
This works in multiple unixes, not only linux, for different paths. On solaris, if you do not have which, you can use: ksh whence -p anypath/a_command.sh | sed "s|^./|$(pwd)|" ksh whence -p Show Sample Output
Will print the host associated with the current stdin. This is useful to set the DOIT_SERVER for the doit remote execution agent ( http://www.chiark.greenend.org.uk/~sgtatham/doit/ ) export DOIT_HOST=$(who -m | sed 's/.*(\(.*\)).*/\1/') Note that SSH_CLIENT variable can be lost if you use su or sudo (if set to reset vars) Show Sample Output
It will return the absolute location of the called a script. If is in $PATH, it will search it using which.
You can combine this function with this other one: http://www.commandlinefu.com/commands/view/9252/readlink-equivalent-using-shell-commands-and-following-all-links, to get a way to know where is the real location of a called script:
# Returns the realpath of a called command.
whereis_realpath() { local SCRIPT_PATH=$(whereis $1); myreadlink ${SCRIPT_PATH} | sed "s|^\([^/].*\)\$|$(dirname ${SCRIPT_PATH})/\1|"; }
Show Sample Output
This is a equivalent to the GNU ' readlink' tool, but it supports following all the links, even in different directories.
An interesting alternative is this one, that gets the path of the destination file
myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link" | sed "s|^\([^/].*\)\$|$(dirname $1)/\1|"); }
Show Sample Output
If you make a mess (like I did) and you removed all the executable permissions of a directory (or you set executable permissions to everything) this can help.
It supports spaces and other special characters in the file paths, but it will work only in bash, GNU find and GNU egrep.
You can complement it with these two commands:
1. add executable permission to directories:
find . type d -print0 | xargs -0 chmod +x
2. and remove to files:
find . type d -print0 | xargs -0 chmod -x
Or, in the same loop:
while IFS= read -r -u3 -d $'\0' file; do
case $(file "$file" | cut -f 2- -d :) in
:*executable*|*ELF*|*directory*)
chmod +x "$file"
;;
*)
chmod -x "$file"
;;
esac || break
done 3< <(find . -print0)
Ideas stolen from Greg's wiki: http://mywiki.wooledge.org/BashFAQ/020
Using gentoo prefix portage I got in a situation where some packages did not contain the needed RPATH variable. This command helped me to find out which ones I should recompile Show Sample Output
It can work for message queue, semaphore set or shared memory just changing the parameter.
AIX lssec does not print the password attribute by policy # lssec -c -f /etc/security/passwd -s an_user -a password 3004-697 Attribute "password" is not valid. To get the password, you have to parse the /etc/security/passwd. You can reuse this password using chpasswd: echo "otheruser:D9oKC1v3VUt/I" | chpasswd -c -e -R compat Show Sample Output
Based on the execute with timeout command in this site. A more complex script: #!/bin/sh # This script will check the avaliability of a list of NFS mount point, # forcing a remount of those that do not respond in 5 seconds. # # It basically does this: # NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH) # TIMEOUT=5 SCRIPT_NAME=$(basename $0) for i in $@; do echo "Checking $i..." if ! perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $i" > /dev/null 2>&1; then echo "$SCRIPT_NAME: $i is failing with retcode $?."1>&2 echo "$SCRIPT_NAME: Submmiting umount -fl $i" 1>&2 umount -fl $i; echo "$SCRIPT_NAME: Submmiting mount $i" 1>&2 mount $i; fi done
Based on the execute with timeout command in this site. A more complex script: #!/bin/sh # This script will check the avaliability of a list of NFS mount point, # forcing a remount of those that do not respond in 5 seconds. # # It basically does this: # NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH) # TIMEOUT=5 SCRIPT_NAME=$(basename $0) for i in $@; do echo "Checking $i..." if ! perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $i" > /dev/null 2>&1; then echo "$SCRIPT_NAME: $i is failing with retcode $?."1>&2 echo "$SCRIPT_NAME: Submmiting umount -fl $i" 1>&2 umount -fl $i; echo "$SCRIPT_NAME: Submmiting mount $i" 1>&2 mount $i; fi done
I like much more the perl solution, but without using perl. It launches a backgroup process that will kill the command if it lasts too much. A bigger function: check_with_timeout() { [ "$DEBUG" ] && set -x COMMAND=$1 TIMEOUT=$2 RET=0 # Launch command in backgroup [ ! "$DEBUG" ] && exec 6>&2 # Link file descriptor #6 with stderr. [ ! "$DEBUG" ] && exec 2> /dev/null # Send stderr to null (avoid the Terminated messages) $COMMAND 2>&1 >/dev/null & COMMAND_PID=$! [ "$DEBUG" ] && echo "Background command pid $COMMAND_PID, parent pid $$" # Timer that will kill the command if timesout sleep $TIMEOUT && ps -p $COMMAND_PID -o pid,ppid |grep $$ | awk '{print $1}' | xargs kill & KILLER_PID=$! [ "$DEBUG" ] && echo "Killer command pid $KILLER_PID, parent pid $$" wait $COMMAND_PID RET=$? # Kill the killer timer [ "$DEBUG" ] && ps -e -o pid,ppid |grep $KILLER_PID | awk '{print $1}' | xargs echo "Killing processes: " ps -e -o pid,ppid |grep -v PID | grep $KILLER_PID | awk '{print $1}' | xargs kill wait sleep 1 [ ! "$DEBUG" ] && exec 2>&6 6>&- # Restore stderr and close file descriptor #6. return $RET }
It will parse the unique_id stanza in ODM database to get the DMX id. Show Sample Output
It will change the reserve_lock attribute to all AIX EMC disk attached.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: