Posts Tagged: bash


8
Dec 11

Guide to Persistent Reverse SSH Shells and Port Forwards

Idiot proof setup for persistent reverse shells / port forwards (same thing) under a Ubuntu VM remote and my Dreamhost server, but should apply to nearly* all *nix’s

Continue reading →


1
Jun 10

Customised User Directories in Ubuntu

I’ve been doing alot of messing around in Ubuntu recently and there are lots of tweaks I like to make. One of them being to show the contents of my home folder as my desktop; I don’t need any more pointless folders….

Continue reading →


31
May 10

Automagic Kernel Cleaning under Ubuntu

Sick of having dozens of old kernels sitting under your /boot/ dir? Want a simpler boot-life? Well we’ve got the solution for you. Continue reading →


9
Apr 10

Listing just dot-files

Its a problem that I’ve come across, and I’m not the only one, so heres what works for me to find those pesky files that start with a .
ls -a | egrep -i "^\."

This only works in the current working directory, which is the normal usage.

FYI the reason that this is problematic is that the ‘.’ symbol is a single character wildcard; most people are familiar with the asterisk ’*’ indicating ‘anything, however long’, whereas the ‘.’ means ‘any single character’.

The command works by looking only at the first character of the file (‘^’, thats called a caret) and then removing the special meaning of ‘.’ by escaping it with the slash.

Update:18/4/10
@stevebiscuit correctly pointed out that the -i flag is unnecessary.

-iinstructs egrep to ignore the case of any matches, so that ‘HeLlO’ matches if you egrep -i for ‘hello’. Since there is no case for the ‘.’ symbol, the -i is pointless.


23
Mar 10

Chmod on lots of files

My lil-NAS has plenty of space but is maddeningly underpowered.

I came across a permissions issue where, depending on how the files in question got there, they would not be accessible to my windows boxes because they were owned by root (I have no doubt that its my fault!)

So, first attempt was nice and easy.

$chown -R smbusr:smbusr *

But this was taking a horrific amount of time, so I thought “There must be a better way”.

Chown does whatever you tell it to do, whether its needed or not. So why not check that first with ‘find’.

$find . -user badnastyawkwarduser -exec chown -R smbusr:smbusr {} \;

and it worked brilliantly!

If you have any shortcuts, let me know in the comments!


12
Mar 10

Line Parsing Reminder (Duplicate removal)

So, say you have a long list of instruction (like multiple apt-get install lines) and you want to eliminate common words?

Continue reading →


6
Nov 08

MBWE Fuel Gauge -> Speedometer conversion

The Fuel gauge on the front of my MBWE is fairly useless, noone cares, so why not repurpose it as a speedometer?

first, stop it displaying the “fuel” Stolen from http://kyyhkynen.net/stuff/mybook/reduce_disk_usage.php

Disable the service that displays the disk usage with the leds in the front panel of your MBWE. Admit it, the feature is pretty much useless and because the service has to check the amount of free space on the disk(s), it is causing disk access.

In order to prevent the service from starting during boot, edit /etc/init.d/S15wdc-fuel-gauge. Comment out this line:

$FGD &

Then stop the service:

# /etc/init.d/S15wdc-fuel-gauge stop
Once all thats done, this is my script (The ultimate in lazy)
#!/bin/bashINITIAL_RX=`cat /sys/class/net/eth0/device/net:eth0/statistics/rx_bytes`sleep 10FINAL_RX=`cat /sys/class/net/eth0/device/net:eth0/statistics/rx_bytes`DELTA_RX=`expr $FINAL_RX - $INITIAL_RX`KBPS_RX=`expr $DELTA_RX / 10240 ` let "RESULT = $KBPS_RX / 3"echo $RESULT > "/sys/devices/platform/wdc-leds/leds:wdc-leds:fuel-gauge/brightness"
The 3 in there is the scaling factor between the kbps download and the number of lights on. Since I'm not often downloading any faster than about 400kbps, and when i am im not really worried about i 0 to 100: lights one led (5 o’clock) 100 to 150: lights two leds (5 and 7 o’clock) 150 to 200: lights three leds (5, 7 and 9 o’clock) 200 to 250: lights four leds (5, 7, 9 and 11 o’clock) 250 to 280ish: lights five leds (5, 7, 9, 11 and 1 o’clock) 280ish and more: lights all leds. I have the whole thing running as a cronjob every 5 minutes, do that urself

24
Sep 08

Primers Coming Up

Thru my work I’m thrown into alot of technologies that i dont nearly know enough about and as with alot of tech related things, the education scene is basic basic basic..GURU with little or no gradiation, so what I’m going to do is post what i learn when i learn it and where i learn it from and hopefully it’ll be useful for someone else, and I’ll also take the opportunity to rehash stuff I’ve already done.

ATM I’ll probably be doing Bash scripting, Perl Scripting, XML, and whatever UNIX stuff comes up whenever I’m writing, but for now and for a relativly simple start; X display fowarding…
This is the setup: Linux/Unix based “client” and “server”; in my case I have headless systems that i fiddle with from time to time, but after a while vim just becomes a pain, and as for viewing html files etcetc copying things back and forth is a pain in the ass.
The solution is already there; From its beginning the X server has always been client server based on some level. Basically what were gonna do is tell the server to use the client as an X display; this is controlled thru an environment variable, strangly called DISPLAY
Lets assume were using SSH. *nix SSHd has a simple system for fowarding and routing the relevent X ports (these wont show up in your “tunnels” tab if your using something like putty, but you shouldnt be using putty anyway)
Theres two versions of this fowarding ability, X and Y. in a nutshell, X is compressed and encrypted. Y isnt. On slow links, Y is probably your best bet, also some servers dont support the X flag. Also also, some sysadms disable this X fowarding.
Anyway, to the point. 
login to the server thusly
client# ssh user@server -X
then when you get a shell check to see if DISPLAY isnt already set (some servers are good enough to do this for you)
server# echo $DISPLAY
if your lucky it’ll say localhost:10.0
otherwise it’ll probably say :0.0 or something similar
If your in this unlucky situation, just enter
server# DISPLAY=localhost:10:0
then try it out, by running the clock and forking it into the background (&)
server# xclock &
Job done. Later

14
Sep 08

Long Extended Break: Hardware Update


So, gonna do a quick write up on my current setup.

Ok, from the top:
Linksys WRT54GL DD-WRT v24 std firmware (also running on the bottom right screen)
Generic Wireless headphones (not used since i heard someone else on the channel :P )
top screens : Windows server 2008 AMD Athlon X2 64 6000+ on an Nvidia MCP 65 based motherboard carrying 6GB, with the dangerous RAID 0 arrangement of two 500GB sata drives and an IDE 320GB for essential backups. (this system is hidden, lol)
The bottom two screens run off of an old Toshiba Laptop that i “repurposed”, more or less the keyboard has been removed and the screen flipped around and re positioned, Intel Celeron something or other, 512 MB memory, 60 GB HDD, running Ubuntu Hardy Heron that i mainly use for chat, downloads, news, system monitoring and notes.
Fairly standard hidden speakers and everythings as hidden so i get to be messy the rest of the time.
As for functionality, i use the laptop as an always on remote access hub that also lets me dial into work from anywhere. Also, since the laptop is keyboard mouseless, I use synergy to automatically start the client on the laptop (using the desktop as the server)
FYI easy enough to set up, just insert this:
/usr/bin/killall synergyc
/usr/bin/synergyc (server)
in these
/etc/gdm/Init/Default
/etc/gdm/PostLogin/Default
/etc/gdm/PostSession/Default
/etc/gdm/PreSession/Default
And this more or less starts and stops the server at every stage of bootup and login (note, you are not going to get to play with BIOS options et al, read the synergy FAQ
Anyway, Otherwise, I’ve been working on alot of bash script that I will post about separatly, but I am going to be learning perl so i will hopefully be using this thing alot more than usual.
Later guys

12
May 08

Folding Code

I’ve been folding for a while now, and I’d previously written a really very cobbled together way of parsing my unitinfo.txt files, but, searching for something to do other than revise, I’ve written a similarly cobbled together but much shorter way of parsing my folding progress and telling me (as in speech) how far its going.

Required: Espeak, basic bash knowledge to adjust.

note: the espeak adjustments are just personal preference, so change them at will.

Its kinda a cheat cus it calls itself but isnt recursive. I’m just lazy


#!/usr/bin/env bash
case "$1" in
"-v")
points | espeak --stdin -s200 -v en+f4
exit
;;
"-w")
points | espeak --stdin -s200 -v en+f4 -w $2
exit
;;
*)
echo "Folding Stats at "&& date +%H:%M
echo "CPU1:" && cat /var/folding/foldingathome/CPU1/unitinfo.txt | grep Progress | cut -d'[' -f1 | cut -d' ' -f2
echo "CPU2:" && cat /var/folding/foldingathome/CPU2/unitinfo.txt | grep Progress | cut -d'[' -f1 | cut -d' ' -f2
exit
;;
esac

it doesnt look very pretty on the console but i think it sounds alright.

Better get some calculus done

::Edited for new version of code with wavfile output


Load Times Plugin made by Ares Free Download