You are not logged in.
It's dirty, but useful for quick encryption/decryption of individual files (like the text file with the credit card numbers
)
Here's my version
pw ()
{
gpg -d $HOME/pathtofile/passwords.exp.asc | gawk 'BEGIN { FS = ""; RS = ""; IGNORECASE = 1};
/'"$@"'/ {print $0}'
}
Last edited by skanky (2010-08-10 09:18:54)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
I just have this vim-plugin.
Then i simply encrypt a file with gpg, and hence on i can do "vim file.gpg" and vim handles decryption and encryption when i save and quit.
Ogion
(my-dotfiles)
"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
"Enlightenment is man's leaving his self-caused immaturity." - Immanuel Kant
Offline
I run this on a web server as a per-minute cron job to randomly execute a PHP script in the /home/rt_cron directory - note that the if clause makes sure there are never two scrips running simultaneously (sexy, I know!).
if [ $(ps aux | grep /home/rt_cron | grep -v grep | wc -l) -eq 0 ] ; then
rm -r /home/rt_temp/*;
scripts=(`ls /home/rt_cron/*.php`);
php -f ${scripts[$((RANDOM%${#scripts[*]}))]};
fi
Offline
I run this on a web server as a per-minute cron job to randomly execute a PHP script in the /home/rt_cron directory - note that the if clause makes sure there are never two scrips running simultaneously (sexy, I know!).
if [ $(ps aux | grep /home/rt_cron | grep -v grep | wc -l) -eq 0 ] ; then rm -r /home/rt_temp/*; scripts=(`ls /home/rt_cron/*.php`); php -f ${scripts[$((RANDOM%${#scripts[*]}))]}; fi
Except that...
1) Your test to find if the script is already running is prone to failure in a variety of ways, and your test is overly complex. grep will return true when it finds a result, so there's no need to wrap the whole thing in [[ ]] and pipe to wc just to count the lines. etc etc etc.. use a lockfile.
2) You're trying to parse the output of ls. Shorten it up:
scripts=(/home/rt_cron/*.php)
Offline
#! /usr/bin/perl
foreach my $key (keys %ENV) {
print "-----\n$key \n $ENV{$key}\n";
}
print "-----";
A quick hack I use to display my environmental variables whenever I need to see them. Yes, I know there's probably a command for it but for some reason I can never remember it 0.o
If you're reading this; you're awesome.
Offline
#! /usr/bin/perl foreach my $key (keys %ENV) { print "-----\n$key \n $ENV{$key}\n"; } print "-----";
A quick hack I use to display my environmental variables whenever I need to see them. Yes, I know there's probably a command for it but for some reason I can never remember it 0.o
perl -E 'say for%ENV'
env
Offline
perl -E 'say for%ENV'
env
Know the first one (and use it) but can never remember the second one for some reason; I think perl programming has greatly retarded my CLI skills
Thanks anyways.
If you're reading this; you're awesome.
Offline
I run this on a web server as a per-minute cron job to randomly execute a PHP script in the /home/rt_cron directory - note that the if clause makes sure there are never two scrips running simultaneously (sexy, I know!).
if [ $(ps aux | grep /home/rt_cron | grep -v grep | wc -l) -eq 0 ] ; then rm -r /home/rt_temp/*; scripts=(`ls /home/rt_cron/*.php`); php -f ${scripts[$((RANDOM%${#scripts[*]}))]}; fi
I'm not sure what you have in your rt_temp folder, and it may not matter in this instance, but in general, using a predictable file name for temp files/folders on a web server is a know security concern.
I use the fantastic program mktmp in all my scripts to create temporary files and folders. Its super easy to use (man mktmp).
Offline
it's an audio converter that converts to m4a aac files.
I've got all my music stored as an albums stored in a folder and tracks are named like this
01 A Wise Birthgiver.mp3
02 Wall Of Water.mp3
03 Great Work Of Ages.mp3
04 Deconsecrate.mp3
06 Psychic Horns.mp3
07 Key To The Storms.mp3
08 Anti.mp3
So, i copy the script into this folder, set up the output bitrate I need, and number of tracks i want to convert, and launch.
Requirements:
neroaacenc
ffmpeg
#!/bin/bash
for i in {1..8}
do
if [ $i -lt 10 ]; then ffmpeg -i 0$i* -acodec pcm_s16le 0$i.wav
else ffmpeg -i $i* -acodec pcm_s16le $i.wav
fi
if [ $i -lt 10 ]; then neroaacenc -if 0$i.wav -br 128000 -of 0$i.m4a
else neroaacenc -if $i.wav -br 128000 -of $i.m4a
fi
if [ $i -lt 10 ]; then rm 0$i.wav
else rm $i.wav
fi
done
and the output files are
01.m4a
02.m4a
03.m4a
...
Offline
My simple hibernation script called 'sleeper'. When I wanna go sleep and leave the music running for some time, this hibernates after some time has passed.
#!/bin/bash
echo -n "Go into hibernation in [minutes]: "
read MINS
let "SECS = $MINS * 60"
echo "Going into hibernation in $MINS mins ($SECS secs)..."
sleep $SECS && ncmpcpp stop && echo 'password' | sudo -S hibernate -F /etc/hibernate/tuxonice.conf
I've just realized that I should implement an mpd stop feature, also, so I did it on the fly now.
Offline
I use something similar in my bashrc:
sleeptimer(){
local min=${1:-"90"} name=${2:-"mplayer"}
echo "DISPLAY="$DISPLAY" xset dpms force off && pkill "$name | \
at now + $min minutes 2>/dev/null
}
Offline
wgetM - a simple download "manager" for wget
Well, of course it's not a real download "manager". It just downloads files and sorts them according to the file extension. I wrote it to be used with Firefox's "FlashGot" extension (I call it with "urxvt --geometry 80x1 -e bin/wgetm [ url ]", gives me a nice one-line urxvt showing just the progressbar), but it works just as well as stand-alone.
It's really simple and easily extensible. Doesn't support a lot of file types yet, I just finished writing it, and I'll add some more along the way.
Usage: wgetm FILES
#!/bin/bash
#===================================================
#
# wgetM
#
#===================================================
# A simple download "manager" for wget
#---------------------------------------------------
# Config ===========================================
BASEDIR='/home/christian/Downloads/Firefox/'
TMPDIR='temp/'
ARCHIVEDIR='Archive/'
MUSICDIR='Musik/'
PICTUREDIR='Bilder/'
TORRENTDIR='Torrents/'
VIDEODIR='Videos/'
OTHERDIR='Andere/'
# Config End =======================================
# Download Files
cd $BASEDIR$TMPDIR
wget $@
# Sort Files
for f in *
do
case $f in
# Archives
*.7z | *.7z.* | *.ar | *.jar | *.part* | *.rar | *.rar.* | *.tar | *.tar.* | *.zip )
mv $f $BASEDIR$ARCHIVEDIR ;;
# Music
*.ape | *.flac | *.mp3 | *.mp4 | *.m4a | *.m4r | *.oga | *.ogg | *.wma | *.wav )
mv $f $BASEDIR$MUSICDIR ;;
# Pictures
*.arw | *.bmp | *.gif | *.jpeg | *.jpg | *.png | *.raw | *.svg | *.tif | *.tiff )
mv $f $BASEDIR$PICTUREDIR ;;
# Torrents
*.torrent )
mv $f $BASEDIR$TORRENTDIR ;;
# Videos
*.avi | *.flv | *.m4v | *.mkv | *.mpeg | *.mpg | *.ogv | *.wmv )
mv $f $BASEDIR$VIDEODIR ;;
# Others
* )
mv $f $BASEDIR$OTHERDIR ;;
esac
done
Last edited by k3ttc4r (2010-08-18 10:04:14)
Offline
I don't know if this qualifies as a command line utility, but here is a simple script to help dmenu launch terminal applications.
#!/bin/bash
term="urxvtc"
nf="#efefef"
nb="#2c2c2c"
sb="#2c2c2c"
sf="salmon"
font="-*-proggycleanszcp-*-*-*-*-*-*-*-*-*-*-*-*"
apps=$(cat ~/.dmenu_cache)
cmd=$(dmenu -nb $nb -nf $nf -sb $sb -sf $sf -fn $font <<< "$apps")
case ${cmd%% *} in
ncmpcpp) exec $term -e ncmpcpp;;
mutt) exec $term -e mutt;;
vim) exec $term -e vim;;
ranger) exec $term -e ranger;;
*) exec $cmd
esac
If you add an application to the list at the bottom, dmenu launches it in the specified terminal, otherwise it launches it normally. (Something like this might exist already, but I couldn't find it anywhere.)
Last edited by splittercode (2010-08-19 01:22:24)
Offline
I remember seeing this somewhere on here before, in fact it's probably in this thread, but I find this very useful:
service() {
sudo /etc/rc.d/$@
}
I save it as a bash script, and zsh picks up the possible daemons and their options with its magical autocomplete. Much easer for me than typing out the full path.
Offline
This is a project I made before I knew about FlexGet. I think I'll keep working on it though, at the very least clean it up.
podcastr:
#!/usr/bin/env python
import feedparser, os, errno, urllib
def mkdir(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
raise
# Config
podcastfolder = '/mnt/Music_1'
podcasts = {'SYSK':'http://www.howstuffworks.com/podcasts/stuff-you-should-know.rss',
'STDWYTK':'http://www.howstuffworks.com/podcasts/stuff-they-dont-want-you-to-know.rss',
'LINUXOUTLAWS':'http://feeds.feedburner.com/linuxoutlaws'}
# /Config
# 256-colored output via trapd00r/dmz's xcolors
i = 202
for key, value in podcasts.items():
mkdir(podcastfolder + "/" + key)
podcast = feedparser.parse(value)
url = podcast['entries'][0]['enclosures'][0]['href']
filename = url.split('/')[-1] # get last part of list, the file name
fullpath = podcastfolder + "/" + key + "/" + filename
if os.path.isfile(fullpath) == False:
print "\033[38;5;%imDownloading: %s > %s/%s" % (i,filename,podcastfolder,key)
urllib.urlretrieve(url, fullpath)
elif os.path.isfile(fullpath) == True:
print "\033[38;5;%im%s is up to date." % (i,podcast['feed']['title'])
i += 1
# NAME
podcastr - A Python podcast updater
# SYNOPSIS
podcastr does not use arguments in this release.
# NOTICES
+ Podcastr does not include a configuration file or support multiple file
downloads within a podcast in this release.
+ The file podcastr must be edited with the appropriate information in this
release.
# REQUIREMENTS
python 2.5+ (Arch Official Repositories: `python`)
urllib module for python (Arch User Repository: `python-urljr`)
feedparser module for python (Arch Official Repositories: `python-feedparser`)
currentproblem: none.
Offline
My simple hibernation script called 'sleeper'. When I wanna go sleep and leave the music running for some time, this hibernates after some time has passed.
#!/bin/bash echo -n "Go into hibernation in [minutes]: " read MINS let "SECS = $MINS * 60" echo "Going into hibernation in $MINS mins ($SECS secs)..." sleep $SECS && ncmpcpp stop && echo 'password' | sudo -S hibernate -F /etc/hibernate/tuxonice.conf
I've just realized that I should implement an mpd stop feature, also, so I did it on the fly now.
GNU's sleep(1) (coreutils) supports time expressions with prefixes like m for minute, h for hour, etc..
You can just let the user specify a string like that, and pass it directly to sleep(1).
#!/bin/dash
echo 'suffix s (or nothing) for seconds, m for minutes, h for hours, d for days; expressions can be catenated'
echo -n 'Hibernate in: '
read time
sleep "$time" && ncmpcpp stop && echo 'password' | sudo -S hibernate -F /etc/hibernate/tuxonice.conf
I was halfway into implementing checking against wrong input and auto-detecting the unit for some nice output, but then remembered that catenated expressions like "1h 20m 30s" are also supported, and that's hard as hell to parse.
``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein
Offline
A handy shell script to set the backlight brightness on a netbook using the Poulsbo chipset and PSB driver.
#! /bin/sh
sudo sh -c "echo $1 > /sys/class/backlight/psblvds/brightness"
Simply save it as brightness.sh, and give it executable permissions. Then you can use it like so:
Set brightness to minimum:
./brightness.sh 0
Set brightness to half:
./brightness.sh 50
Sudo may obviously ask for your password, so you have to be in the sudoers file.
I've tested this with both Bash and Dash.
This "code" is released under the GPL v3 license. http://www.gnu.org/licenses/gpl.html
Last edited by mulenmar (2010-08-21 18:01:23)
Offline
I remember seeing this somewhere on here before, in fact it's probably in this thread, but I find this very useful:
service() { sudo /etc/rc.d/$@ }
I save it as a bash script, and zsh picks up the possible daemons and their options with its magical autocomplete. Much easer for me than typing out the full path.
I use this, it should work on distros that use init.d rather than rc.d also. (well I know it works on gentoo and arch)
# daemon controls
if [ -d /etc/rc.d ]; then
SERLOC="rc.d"
else
SERLOC="init.d"
fi
start()
{
for arg in $*; do
sudo /etc/$SERLOC/$arg start
done
}
restart()
{
for arg in $*; do
sudo /etc/$SERLOC/$arg restart
done
}
stop()
{
for arg in $*; do
sudo /etc/$SERLOC/$arg stop
done
}
Last edited by gazj (2010-08-21 18:56:59)
Offline
just wrote this to try out the "read" command, it lists the current running screen sessions, then asks you to select the number, then resumes the one you sellect, right now i have to count the lines and then type which line its on, i dont know how to get bash or grep to number lines yet.
#!/bin/bash
##output available screen sessions
screen -ls | egrep "(Detached)" | cut -f2 -d'.'| cut -f1 -d'(' | nl
##ask user which screen they want to use
echo -e "can you type the number you want to resume: \c "
read number
screen -r $(screen -ls | egrep "(Detached)" | head -n $n
example output:
mark@torrentslave:~$ ./screenresume.sh
1 esniper-blackberry
2 esniper-cpu
can you type the number you want to resume:
so typing 1 would resume the esniper-blackberry , and 2 would resume esniper cpu.
i find this pretty usefull, as its not uncommon for me to have 5 of more screen sessions running at a time.
Last edited by markp1989 (2010-08-22 21:09:04)
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
just wrote this to try out the "read" command, it lists the current running screen sessions, then asks you to select the number, then resumes the one you sellect, right now i have to count the lines and then type which line its on, i dont know how to get bash or grep to number lines yet.
Pipe the output through nl to number the lines.
Last edited by Stebalien (2010-08-22 21:08:45)
Offline
karmp1989 wrote:just wrote this to try out the "read" command, it lists the current running screen sessions, then asks you to select the number, then resumes the one you sellect, right now i have to count the lines and then type which line its on, i dont know how to get bash or grep to number lines yet.
Pipe the output through nl to number the lines.
thanks, that done exactly what i wanted., just gone edit my post to include the change
anyone else notice that my username got jumbled up in the quote?
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
Convert CSV files to HTML tables. Catenate multiple files from the command line into a single output or read from STDIN.
It was pure Bash until I realized that blank fields were causing issues, and had to throw in the sed call (which could probably be written with PEs).
#!/bin/bash
NUMFIELDS=0
OUT=()
to_html() {
local LC=0 # line counter in case of error
while IFS=',' read -r -a items; do
(( ++LC ))
OUT+=("\t<tr>\n") # start row
# skip blank lines, but not lines with empty fields
(( ${#items[@]} == 0 )) && continue
# assert: all rows are same number of columns
(( NUMFIELDS == 0 )) && NUMFIELDS=${#items[@]}
if (( NUMFIELDS != ${#items[@]} )); then
echo "error: Malformed CSV ($file: line $LC). Expected $NUMFIELDS fields, found ${#items[@]}." >&2
exit 1
fi
# output each column, stripping NULL tokens
for item in "${items[@]}"; do
OUT+=("\t\t<td>${item/==NULL==/}</td>\n")
done
OUT+=("\t</tr>\n") # end row
# replace blank fields with a dummy value so read doesn't skip them
done < <(sed 's/^,/==NULL==,/;
s/,,/,==NULL==,/g;
s/,$/,==NULL==/' <&6)
}
OUT+=("<table>\n") # header
# use a new FD to unify where to read from
if (( $# == 0 )); then
exec 6<&0
to_html
else
for file; do
exec 6< "$file"
to_html
exec 6<&-
done
fi
OUT+=("</table>\n") # footer
echo -e "${OUT[@]}"
Offline
If you dont know what to put in that latest commit msg...
#!/usr/bin/perl
# wtc - get random retarded commit msgs
use strict;
use LWP::Simple;
for(get('http://whatthecommit.com/')) {
if(m;<p>(.+)\n</p>;) {
print $1,"\n";
}
}
punpack - extract a show, play it, delete the unpacked file and keep track of
what shows I've seen.
#!/usr/bin/perl
# chmod, unpack, watch, delete
use strict;
use Cwd;
use File::Find;
my $mp = 'mplayer -msgcolor';
my $pwd = shift // getcwd();
my $permdir = 01742; # -rwxr---wT
chmod($permdir, $pwd);
my $tempdir;
$pwd =~ m/^((?:\/[^\/]+){2}\/).*/ and $tempdir = "$1.punpack-temp";
$tempdir = '/tmp/' if(@ARGV);
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
File::Find::find({wanted => \&wanted}, $pwd);
sub wanted {
/^.+(?:part00)?\.rar/
&& doexec(0, "rar x \"{}\" $tempdir/ && $mp $tempdir/* && rm -rv $tempdir/");
}
sub doexec ($@) {
my $ok = shift;
my @command = @_; # copy so we don't try to s/// aliases to constants
for my $word (@command) {
$word =~ s#{}#$name#g;
}
if ($ok) {
my $old = select(STDOUT);
$| = 1;
print "@command";
select($old);
return 0 unless <STDIN> =~ /^y/;
}
chdir($pwd); #sigh
system(@command);
chdir $File::Find::dir;
return !$?;
}
Last edited by dmz (2010-08-23 19:25:56)
Offline
Not really a utility, but I've found it very useful.
printf "%${COLUMNS}s\r"
If output after a command, it ensures that non-newline-terminated output does not mess with your prompt. It works by emitting ${COLUMNS} (terminal width) spaces to move to a new line if the current line is not empty, then a carriage return to move to column 0. If you put this in your PS1, remember to surround the command with \[...\] so the shell doesn't miscalculate the line length. (Protocol for non-bash shells may be different.)
Someone might have said this already, but I didn't bother to check the 50+ pages of this thread.
Now, back to lurking for another few months...
Last edited by Peasantoid (2010-08-25 04:54:59)
Offline