You are not logged in.
Please give me some feedback if you notice any security issues with this script. Hashing would make it more secure, but I'm not good at that stuff.
I would recommend looking at pwsafe
Offline
Make a wrapper script around it that invokes gpg
Or an alias.
alias pw='gpg -d $HOME/file.asc | grep'
To edit the file:
vi $HOME/file.asc
Offline
Why not just use pwsafe?
Offline
Why not just use pwsafe?
I'm currently using a gpg'd file as I have a load of passwords in keepassx format but don't really want to use keepassx any more - (for no real rational reason probably, but let's go with that for now) and I really couldn't be bothered to type them all in - esp. as I have to type in my passphrase for every single one. If anyone knows of a way to import numerous items from keepassx to pwsafe, then I'd love to hear about it.
Otherwise, to keep this on topic, I like that xclip script and may well have a look at combining it with gpg, if I get a few minutes.
"...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 wanted an excuse to use paste, and I find that I sometimes forget what FS I'm using on my partitions, so I whipped up an "improved" df command:
#!/bin/bash
paste <(echo "Type";/bin/mount | sed -n '/^\/dev/s/.*type \([a-z0-9]*\) .*/\1/p') <(/bin/df -h | grep -E "^\/dev|^Filesystem")
Example output:
Type Filesystem Size Used Avail Use% Mounted on
btrfs /dev/sdb3 149G 2.4G 147G 2% /
ext2 /dev/sda1 92M 12M 75M 14% /boot
ext4 /dev/sdb2 20G 2.5G 17G 14% /home
ext4 /dev/sdc1 367G 56G 293G 16% /mnt/Destruction
btrfs /dev/sdb4 200G 21G 180G 11% /mnt/Entropy
btrfs /dev/sdd1 932G 502G 430G 54% /mnt/Gluttony
edit: Fix alignment. Silly BBS.
Last edited by falconindy (2010-04-08 17:16:27)
Offline
Does 'df -Th' not do the same?
Offline
steve___ wrote:Does 'df -Th' not do the same?
!@#$%^!@#$
Ah well.
thanks to both of you. I also have been typing 'mount' and 'df -h' after each other way too many times, without knowing the -T option. So i can definitely understand falconindy's idea to DIY
btw what's this 'paste' thing?
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Nice one line script though, falconindy.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Talking of df.
I've missed an total free/used summary (THAT is for sure not in df... I hope).
So I made this hack, pdf:
#!/usr/bin/perl
# pdf
use strict;
use Filesys::DiskFree;
my $df = Filesys::DiskFree->new;
my @disks = glob('/mnt/*');
push(@disks, '/');
my (@total, @free, @used);
printf("\033[31;1m%11s %11s %12s %9s\033[0m\n",
'MOUNTPOINT', 'TOTAL', 'WASTED', 'FREE');
foreach my $drive(@disks) {
$df->df();
printf("%-13s | %6.2f GB | %6.2f GB | %6.2f GB\n",
$drive, &btogb($df->total($drive)), &btogb($df->used($drive)),
&btogb($df->avail($drive)));
push(@total, $df->total($drive));
push(@free, $df->avail($drive));
push(@used, $df->used($drive));
}
printf '-' x 50;
my $c = "\033[34;1m";
my $c0 = "\033[0m";
printf("$c\nSUMMARY$c0\n FREE: %-5.2f GB\n USED: %.2f GB\nTOTAL: %.2f GB\n",
&calculate(@free), &calculate(@used), &calculate(@total));
sub calculate {
my @total = @_;
my $sum;
foreach my $total(@total) {
$sum += $total;
}
return &btogb($sum);
}
sub btogb {
my $foo = shift;
return $foo/1024/1024/1024;
}
I also wrote a tailer for the Common Log Format (apache, lighttpd etc) that'll make it a lil bit easier to see what's going on using color codes. There was some guy in #archlinux that wanted this, but I forgot who, so I hope he see this.
#!/usr/bin/perl
use strict;
use File::Tail;
my $log = shift;
my $line = "";
my $tail = File::Tail->new(name=>$log,
maxinterval=>3,
adjustafter=>3,
interval=>0,
tail=>100
);
while(defined($line=$tail->read)) {
my $e = "(.+?)";
$line =~ /^$e $e $e \[$e:$e $e\] "$e $e $e" $e $e/;
my $ip = $1;
my $ref = $2;
my $name = $3;
my $date = $4;
my $time = $5;
my $gmt = $6;
my $request = $7;
my $file = $8;
my $ptcl = $9;
my $code = $10;
my $size = $11;
$code = "\033[38;5;240m$code\033[0m" if $code == 404;
$code = "\033[38;5;155m$code\033[0m" if $code == 200;
$code = "\033[38;5;160m$code\033[0m" if $code == 501;
$code = "\033[38;5;208m$code\033[0m" if $code == 301;
$code = "\033[38;5;124m$code\033[0m" if $code == 403;
$code = "\033[38;5;113m$code\033[0m" if $code == 304;
$file = "" if $file =~ /^\/$/;
$file = "\033[38;5;160m$file\033[0m" if $file !~ /([A-Za-z0-9])+/;
$size = "\033[38;5;160m$size\033[0m" if $size > 5;
printf("%s %7s %s %s %60s\n",
$code, $request, $size, $ip, $file);
}
Offline
I also wrote a tailer for the Common Log Format (apache, lighttpd etc) that'll make it a lil bit easier to see what's going on using color codes. There was some guy in #archlinux that wanted this, but I forgot who, so I hope he see this.
pacman -S colortail
//github/
Offline
dmz wrote:I also wrote a tailer for the Common Log Format (apache, lighttpd etc) that'll make it a lil bit easier to see what's going on using color codes. There was some guy in #archlinux that wanted this, but I forgot who, so I hope he see this.
pacman -S colortail
and I suggest tailf $log | ccze
Offline
When ghpoto2 imports photos from my camera they are named something along like "IMG_somenumber.JPG" and often I want to select more than one, but not all of them (usually a range) for some kind of action, so I've come up with this little tool:
#!/usr/bin/env perl
use strict;
use warnings;
my $re;
my $m;
my $cond;
if (@ARGV == 3) {
($re, $m, $cond) = @ARGV;
}
elsif (@ARGV == 2) {
($re, $cond) = @ARGV;
$m = "";
}
else {
print STDERR "pfilt pattern [modifier] condition\n";
exit 1;
}
eval("if (/$re/$m){print if $cond}") for (<stdin>);
e.g if I have the files IMG_0013.JPG IMG_0017.JPG and IMG_0018.JPG and run pfilt 'IMG_(\d+).JPG' '$1>13'
the last two will be printed. I haven't looked into all the flags of grep, and I'm not that fond of awk, so it is possible that I'm reinventing the wheel...but if I learn stuff doing it it is worth it imo.
Last edited by tlvb (2010-04-12 15:39:25)
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
Haters gonna hate...
I guess this is what you'd call hackish code.
#!/bin/sh
#
# mountall.sh: Mount '/dev/$1?*'.
#
# Automatically creates (and later removes) relevant dirs in /mnt.
#
err_usage ()
{
echo "Usage:"
echo "'$(basename "$0")' dev_name [args_to_mount...]"
echo
echo "'dev_name' must be like 'hda', 'sda', 'hdb', 'sdb', etc."
exit 1
}
test $# -lt 1 && err_usage
dev="$1"; shift
clearup="${TMPDIR:-/tmp}"/mountall-clearup--$$
echo > "$clearup" 'rm "$0"'
chmod u+x "$clearup"
{
trap "exec '$clearup' > /dev/null 2>&1" EXIT;
while true; do sleep 30; done
} &
for part in $(ls /dev/"$dev"?* 2> /dev/null)
do
dir=/mnt/"$(basename "$part")"
exists=
test -d "$dir" && exists=yeah || {
echo >> "$clearup" "umount '$dir'; rmdir '$dir'"
mkdir "$dir"
}
mount "$part" "$dir" "$@" 2> /dev/null && {
echo "mounted: $part"
echo >> "$clearup" "printf \"\$(cat /etc/mtab)\" | grep -F '$part $dir' && umount '$dir'"
success=yeah
} || {
test "$exists" || rmdir "$dir"
}
done
test "$success" || { echo "mounted nothing"; exit; }
(edit: Code has been entirely changed. I hadn't tested it, and it was broken to the point of requiring a rewrite.)
Last edited by TaylanUB (2010-04-14 21:17:03)
``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein
Offline
I just wrote this git pre-commit hook. It's intended for those who use git to manage their PKGBUILD files. It forbids all commits that include a PKGBUILD file when the source and install files are not either in git, or also in the commit.
Install it by putting it into .git/hooks/pre-commit and making it mode +x.
Just updated this with a bugfix, should be a bit more robust now
[git] | [AURpkgs] | [arch-games]
Offline
I really gotta test my scripts before publishing them.
The one i posted above is borked really hard. (Will edit in a minute.)
``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein
Offline
Wrote this this morning. (although I've wanted to for a while)
It opens up all files for a project you're working on, identified by the directory's name.
So if you're in directory "foo" it will open up foo.py/foo.pl/foo.c/whatever, and all (local) files it imports/uses/#includes/whatever
#!/usr/bin/perl
#This script opens the files for a project
#It determines the main file from the name of the directory, then opens it and all local modules it relies on in an editor of your choice
#file extensions
# if you add a new language, make sure to add it to the regex (line 30)
$perl_ext="pl|p";
$python_ext="py";
$c_ext="c";
$cpp_ext="cpp|cc";
#import syntax for different languages
$perl_imp="use (\w+)";
$python_imp="import (\w+)|from (\w+) import";
#local includes only. Also note that c++ and c use the same syntax
$c_imp="#include \"(.+)\"";
#map the syntaxes to languages
%import_syntax=($perl_ext=>$perl_imp, $python_ext=>$python_imp, $c_ext=>$c_imp, $cpp_ext=>$c_imp);
#set the editor
$editor = shift || "gedit";
#project name
`pwd`=~/.*\/(.*)/;
$project=$1;
#find the main file
`ls`=~/($project\.($perl_ext|$python_ext|$c_ext))/;
$project_language=$2;
$import=$import_syntax{$project_language};
#open the files
@files=($1);
Find_Dependencies($1);
system("$editor @files");
#recursively search through project files, identifying imported (local) modules
sub Find_Dependencies
{
local *FILE;
open(FILE, shift) or return; #local modules only;
while ($_=<FILE>)
{
if (/$import/)
{
push(@files, $+);
Find_Dependencies($+);
};
};
}
Note that perl can't make local filehandles, hence "local *FILE". Also, I know most IDEs do this for you anyways, but this could open up te files in vim, emacs, gedit, geany, or anything else under the sun. Heck, it could "open" them with cat, too...
Last edited by Chimera (2010-04-18 15:33:42)
Offline
get your global and local ip with this little lua script
#!/usr/bin/env lua
require 'socket.http'
function matchIP( ip_string )
if ip_string then
return '\27[1;32m' .. string.match(ip_string, '%d+%.%d+%.%d+%.%d+')
else
return '\27[1;31mnot connected'
end
end
local ip = {}
ip['local'] = matchIP(io.popen('ip -o -f inet addr show scope global'):read())
ip['global'] = matchIP(socket.http.request('http://www.whatsmyip.us/showipsimple.php'))
for key, val in pairs(ip) do
io.write(':: \27[1;34m'..key..' '..val..'\27[0m\n')
end
os.exit()
Last edited by muunleit (2010-04-19 16:17:38)
"The mind can make a heaven out of hell or a hell out of heaven" -- John Milton
Offline
What is my ip? has an automation address for you to use in scripts. See here: http://www.whatismyip.com/automation/default.asp
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
I posted a handy screen utility a while ago, I changed it a bit since then, mostly that it now uses Imgur and doesn't save the screenshots locally.
function uploadImage {
curl -s -F "image=@$1" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml | grep -E -o "<original_image>(.)*</original_image>" | grep -E -o "http://i.imgur.com/[^<]*"
}
scrot -s "shot.png"
uploadImage "shot.png" | xclip -selection c && rm "shot.png"
#notify-send "Done"
Pretty fast too.
(You should request to get your own key instead of using mine though, but it's no problem if you use it for testing, or minor use.)
Also, I made a script which makes sure only one terminal is running at a time. Very handy when you've bound f.e. Sakura to Alt-T, and use it every time you want a terminal - then you'd usually end up with a good load.
#! /bin/bash
WINTITLE="sakura" # Name of the window (or part of it)
PROGRAMNAME="sakura" # Name of the program, so it can be opened if there's no window currently
# Lists all windows, if there's one containing $WINTITLE it'll return 1, and bring the current instance of the program to the front.
if [ `wmctrl -l | grep -c "$WINTITLE"` != 0 ]
then
wmctrl -a "$WINTITLE"
# Else, it'll launch a new instance
else
$PROGRAMNAME &
fi
# We're good!
exit 0
And then I recently threw this in my bin as c2c, used it a lot..
cat $1 | xclip -selection c
Last edited by Sirupsen (2010-04-22 05:49:41)
Offline
And then I recently threw this in my bin as c2c, used it a lot..
cat $1 | xclip -selection c
Kill the cat. You might be interested in this as well; http://bbs.archlinux.org/viewtopic.php?id=95345
Offline
I use abook for my contacts. One of the advantage is the easy to deal with storage (plain text file). This little script will look-up a contact (or contacts) based on the search term and field (if specified). 99% of the time I use the nick field, so that's my default. I've set-up two formats - plain and latex - newlfm. I use the latter to insert into a newlfm letter template (I call this script from a separate one that inserts the address as returned here and the body as saved in a separate file into the template, then calls pdflatex to generate the letter).
It should be fairly simple to add new output formats as needed and these could be put into separate files for reference from the (g)awk routine. The script has not been checked for portability.
#!/bin/bash
#
# getcontact
#
# Returns a contact's address from
# the addressbook.
# Setup
ADBOOK=$XDG_DATA_HOME/abook/addressbook
SFIELD=nick
while getopts "f:h:t" opt; do
case $opt in
f ) SFIELD="$OPTARG" ;;
h ) echo "Need to add help"
exit 0 ;;
t ) tex="-v astex=1" ;;
\? ) echo "Need to add help"
exit 1
esac
done
shift $(($OPTIND -1))
LOOKUP=${1?"No search term specified"}
echo $LOOKUP
gawk $tex '
# prints address without any formatting
function printPlain(items) {
if ("name" in items) print items["name"]
if ("job_title" in items) print items["job_title"]
if ("department" in items) print items["department"]
if ("organisation" in items) print items["organisation"]
gsub(",", "\n", items["address_lines"])
if ("address_lines" in items) print items["address_lines"]
if ("city" in items) print items["city"]
if ("state" in items) print items["state"]
if ("zip" in items) print items["zip"]
if ("country" in items) print items["country"]
}
# prints address in tex format
function printAsTex(items) {
for (item in items) gsub(/&/, "\\\\&", items[item])
if (items["name"])
address = "\\name{" items["name"] "}%\n\\addr{"
if (items["job_title"])
address = address items["job_title"] "\\\\%\n"
if (items["department"])
address = address items["department"] "\\\\%\n"
if (items["organisation"])
address = address items["organisation"] "\\\\%\n"
if (items["address_lines"]) {
gsub(", *", "\\\\%", items["address_lines"])
address = address items["address_lines"] "\\\\%\n"
}
if (items["city"])
address = address items["city"] "\\\\%\n"
if (items["zip"])
address = address items["zip"] "\\\\%\n"
if (items["country"])
address = address items["country"] "\\\\%\n"
print "\\setadrto{\n" address "}}%"
}
BEGIN { FS = "="; inRec = 0 }
/\[[0-9]+\]/ { inRec = 1 }
/^[:space:]*$/ { inRec = 0
if (addr["'"$SFIELD"'"] == "'"$LOOKUP"'") {
if (astex == 1)
printAsTex(addr)
else
printPlain(addr)
}
else
{
for (item in addr) delete addr[item]
}
}
/.*=.*/ { if (inRec = 1) addr[$1] = $2 }' $ADBOOK
"...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
What is my ip? has an automation address for you to use in scripts. See here: http://www.whatismyip.com/automation/default.asp
thanks, thats usefull.
threw this mail notifier together. will email you if your ip has changed.
#!/bin/bash
ip=$(curl http://www.whatismyip.com/automation/n09230945.asp)
iplog=/tmp/.ip.log
if cat $iplog | grep -q $ip ; then
echo ip is the same as last run
else
echo -e "$(date) : - IP Change. \n\n your new ip address is $ip" | mail -s "[IP change] $ip" Email@domain.com
fi
echo $ip > $iplog
edit....1000th post in thie thread
Last edited by markp1989 (2010-04-22 20:02:39)
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
hrm, i have something quite similar...
#!/bin/bash
#
# pbrisbin 2009
#
# http://pbrisbin.com:8080/bin/checkip
#
###
logger() { echo "$(date +'[ %d %b %Y %H:%M ]') $*" | tee -a "$log"; }
update_dns() {
echo $new > "$ipfile"
wget -O - --http-user=$zuser --http-passwd=$zpass 'http://dynamic.zoneedit.com/auth/dynamic.html?zones=pbrisbin.com' &>/dev/null || exit 1
logger "ip updated $old -> $new"
}
[ -f "$HOME/.credentials" ] && . "$HOME/.credentials" || exit 1
ip_url='http://tnx.nl/ip'
log="$HOME/checkip.log"
ipfile="$HOME/.myip"
touch "$ipfile"
old="$(cat "$ipfile")"
new="$(lynx -dump "$ip_url")"
[ "$old" != "$new" ] && update_dns || exit 0
doesn't email me, but it updates my dns with zonedit and logs the occurrence.
woot! 9th post in this thread!
/binarylol
Last edited by brisbin33 (2010-04-22 20:54:30)
//github/
Offline