Tue 27 May 2014
GAWK script for some work funkyness
Posted by Internat under Bash, Uncategorized
[2] Comments
gawk ‘{if(~ /\.tar/){lasttar=}; if(~ /^filenamehere\.jpg$/){print lasttar; exit;}}’ < internat.txt
Tue 27 May 2014
Posted by Internat under Bash, Uncategorized
[2] Comments
gawk ‘{if(~ /\.tar/){lasttar=}; if(~ /^filenamehere\.jpg$/){print lasttar; exit;}}’ < internat.txt
Tue 23 Oct 2012
Posted by Internat under Bash, Debian, Linux
No Comments
I cant take any credit for this script, I took the orginal from the solar.js.cx page and changed it to meet my requirements.
Here is my version
#!/usr/bin/perl ############################################ ## This software is licensed under the LGPL. ## Visit http://solar.js.cx for more info. ############################################ use Device::SerialPort; use LWP::UserAgent; use Time::Local; use HTTP::Status qw(:constants :is status_message); $debug = 0; $submit = 1; $serial_port = "/dev/ttyr00"; $pvoutput_api ="<apikeyhere>"; $pvoutport_systemid = "<systemkeyhere>"; $serial_lock = "/tmp/ttyr00.lock"; ## Wait until unlocked while (-e $serial_lock) { sleep (1); } $serial_port = new Device::SerialPort ($serial_port, "", $serial_lock); $serial_port->baudrate(9600) || die "failed setting baudrate"; $serial_port->parity("none") || die "failed setting parity"; $serial_port->databits(8) || die "failed setting databits"; $serial_port->handshake("none") || die "failed setting handshake"; $serial_port->write_settings || die "no settings"; ## Might need to tweak this if data is truncated. $serial_port->read_const_time(40); $serial_port->write("INV?\r"); ($count, $xantrex_status) = $serial_port->read(255); $serial_port->write("KWHTODAY?\r"); ($count, $xantrex_kwhtoday) = $serial_port->read(255); $serial_port->write("TIME?\r"); ($count, $xantrex_time) = $serial_port->read(255); $serial_port->write("POUT?\r"); ($count, $xantrex_pout) = $serial_port->read(255); $serial_port->close || warn "close failed"; $xantrex_wtoday = $xantrex_kwhtoday * 1000; #$time = timelocal($sec,$min,$hour,$mday,$mon,$year); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon += 1; $date = sprintf "%04d%02d%02d", $year,$mon,$mday; $ptime = sprintf "%02d:%02d", $hour, $min; if ($debug == 1) { print "Current date/time is: $date - $ptime\n"; print "Current inverter status is: $xantrex_status\n"; print "Total KWH today is: $xantrex_kwhtoday\n"; print "Total WH today is: $xantrex_wtoday\n"; print "Current output is: $xantrex_pout\n"; } chomp($xantrex_status); my $length = length($xantrex_status); $length -=1; $status = substr $xantrex_status, 0, $length; if (($submit == 1) && ($status eq "ON")) { if ($debug == 1) { print "Submitting data\n"; } my $ua = new LWP::UserAgent; $ua->default_header( 'X-Pvoutput-Apikey' => $pvoutput_api, 'X-Pvoutput-SystemId' => $pvoutport_systemid ); my $response = $ua->post('http://pvoutput.org/service/r2/addstatus.jsp', { 'v2' => $xantrex_pout, 'v1' => $xantrex_wtoday, 'd' => $date, 't' => $ptime }); my $content = $response->content; if ($debug == 1) { print "$content\n"; } if ($response->is_error) { print "Error updating pvoutput.org $content\r\n"; } }
Thu 27 Oct 2011
Posted by Internat under Bash, Debian, Linux
No Comments
I used to have an encrypted volume on my file server, for storing sensitive things, but after an upgrade to the newest version of Debian, that stopped working. So after some mucking around and getting the old module for cryptoloop put back into my current kernel, I figured i might as well migrate over to the newer version, which uses cryptsetup, losetup, and luks.
Ive shamelessly stolen these commands (although ive changed some of them)from elsewhere..
Create the file system and restricted access.
dd of=/path/to/secretfs bs=1G count=0 seek=8
chmod 600 /path/to/secretfs
Create a loopback device for the file
losetup /dev/loop0 /path/to/secretfs
Creates the volume, asks you for the key, and then creatss the DM mapping
cryptsetup -y luksFormat /dev/loop0
cryptsetup luksOpen /dev/loop0 secretfs
Pad the file so it generates its random data
dd if=/dev/zero of=/dev/mapper/secretfs
Create the filesystem
mkfs.ext3 dev/mapper/secretfs
# Mount the new filesystem in a convenient location
mkdir /mnt/cryptofs/secretfs
mount /dev/mapper/secretfs /mnt/cryptofs/secretfs
And an encrypted volume is setup.
Now how to unmount:
umount /mnt/cryptofs/secretfs
cryptsetup luksClose secretfs
losetup -d /dev/loop0
Remount:
losetup /dev/loop0 /path/to/secretfs
cryptsetup luksOpen /dev/loop0 secretfs
(enter password when prompted)
mount /dev/mapper/secretfs /mnt/cryptofs/secretfs
Now stuff that i can never remember how to do is grow the volume.
Make sure the volume is closed, unmounted etc.
umount /mnt/cryptofs/secretfs
cryptsetup luksClose secretfs
losetup -d /dev/loop0
Add 20gig to the file
dd if=/dev/zero bs=1G count=20 >> /dev/mapper/secretfs
Remount and reopen part of it
losetup /dev/loop0 /path/to/secretfs
cryptsetup lucksOpen /dev/loop5 EncryptedFS
check the FS first
e2fsck -f /dev/mapper/EncryptedFS
once thats done grow it
resize2fs /dev/mapper/EncryptedFS
and your done. You can now open the volume for use
Mon 22 Mar 2010
Trying to use sed in some stuff and i never want to have to write this kinda crap again so..
grep '^D' Filename | sed -e 's/\(^.\{43\}\)0\(.*\)/\1M\2/g'
That looks for any line in “Filename” that starts with D… then if the 44th character is 0, replace it with an M.
kgo.
grep "^D" Filename | sed -e 's/.*/&XX/'
That looks for anything in Filename and adds “XX” to the end of the line..
Another Useful link