Jun 182015
 

I recently had to verify a whole bunch of servers were responding to SNMP and had the correct DNS reverse look ups in Active Directory.
I used this little script so that it would ask me for an IP address and then do a ping, and then if a server was reachable over ICMP, a nslookup if a server responded to the SNMP Query for the system name.
Continue reading »

Share
Nov 142013
 

I wanted to rename a whole bunch of models to transform their names into all lowercase with just the hostname rather than the FQDN.
I used this script to do it with bash and vnmsh. The script will loop through all models found by the query with a model type handle, and then renames then with a vnmsh update command.


#!/bin/bash
export CLIMNAMEWIDTH=70
OldIFS=$IFS
IFS=$'\n'
WORKPATH="/opt/CA/Spectrum/vnmsh"

$WORKPATH/connect

## Pingable
MDLLIST=`$WORKPATH/show models mth=0x10290`
MDLLIST=`echo "$MDLLIST" | grep -vi mname`

for x in $MDLLIST; do
MDLHANDLE=`echo $x | awk -F '[ |.]+' ' { print $1 } '`
MDLNAME=`echo $x | awk -F '[ |.]+' ' { print tolower($2) }'`
echo $MDLHANDLE
echo $MDLNAME

$WORKPATH/update mh=$MDLHANDLE attr=0x1006e,val=$MDLNAME
done
$WORKPATH/disconnect
IFS=$OldIFS

Share
Nov 082013
 

I was adding some new features on PiParted recently and needed a simple file browser for my PiParted script. I couldn’t find anything online for this sort of thing, so I built my own file browser of sorts.

Using whiptail and the output of ls (which isn’t recommended but I’ll get around to posting an updated version of this script sometime), I managed to get a simple file browser to allow a user to pick a file.
I’ll paste bits and pieces of the code to explain it, and then paste the whole function at the end of this post.

This starts off with an if statement to check to see whether a path has been passed to the script. If it hasn’t it will start the listing off at /, Otherwise it will start at the path it had been passed.

function Filebrowser() {
if [ -z $1 ]; then
imgpath=$(ls -lhp / | awk -F ' ' ' { print $9 " " $5 } ')
else
imgpath=$(ls -lhp "/$1" | awk -F ' ' ' { print $9 " " $5 } ')
fi

Next, still checking to see whether it was passed a path, it will show a back button if it was passed a path.

if [ -z $1 ]; then
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select $imgpath 3>&1 1>&2 2>&3)
else
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select ../ BACK $imgpath 3>&1 1>&2 2>&3)
fi

Next, it checks the return value to make sure it was 0 to signify the user didn’t press cancel
After that, it checks the path the user selected to see if it was a directory, if it is then it re-runs the function and passes a path
Otherwise it will determine whether the file selected is the file type that is required, and if it is show that it is about to perform an action. If it’s not the type required, present an error to the user.

RET=$?
if [ $RET -eq 0 ]; then
if [[ -d "/$1$pathselect" ]]; then
Filebrowser "/$1$pathselect"
elif [[ -f "/$1$pathselect" ]]; then
fileout=`file "$1$pathselect"
filename=`readlink -m $1$pathselect`
if [[ $fileout =~ x86\ boot\ sector$ ]]; then
whiptail --yesno --title "! WARNING !" "About to try and automatically resize $filename. Are you sure ?" 10 50
### This bit of the code would be what you want to do after the user has selected the right type of file.
if [ $? -ne 0 ]; then
Filebrowser
fi
else
whiptail --msgbox --title "! ERROR ! ERROR ! ERROR ! " "Selected file is not an image file." 8 44
Filebrowser
fi

And lastly, check to make sure the path that was passed to the script is valid. At the moment, I don’t imagine this script would handle spaces well so you may see this error message when processing directories with spaces in their names.

else
echo pathselect $1$pathselect
whiptail --title "! ERROR !" --msgbox "Error setting path to image file." 8 44
unset base
unset imgpath
Filebrowser
fi
exit 0

And, as promised, the whole code in one big block

Filebrowser() {
if [ -z $1 ]; then
imgpath=$(ls -lhp / | awk -F ' ' ' { print $9 " " $5 } ')
else
imgpath=$(ls -lhp "/$1" | awk -F ' ' ' { print $9 " " $5 } ')
fi
if [ -z $1 ]; then
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select $imgpath 3>&1 1>&2 2>&3)
else
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select ../ BACK $imgpath 3>&1 1>&2 2>&3)
fi
RET=$?
if [ $RET -eq 1 ]; then
## This is the section where you control what happens when the user hits Cancel
AdvancedMenu
exit 0
elif [ $RET -eq 0 ]; then
if [[ -d "/$1$pathselect" ]]; then
Filebrowser "/$1$pathselect"
elif [[ -f "/$1$pathselect" ]]; then
## Do your thing here, this is just a stub of the code I had to do what I wanted the script to do.
fileout=`file "$1$pathselect"`
filename=`readlink -m $1$pathselect`
if [[ $fileout =~ x86\ boot\ sector$ ]]; then
whiptail --yesno --title "! WARNING !" "About to try and automatically resize $filename. Are you sure ?" 10 50
if [ $? -ne 0 ]; then
Filebrowser
fi
else
whiptail --msgbox --title "! ERROR ! ERROR ! ERROR ! " "Selected file is not an image file." 8 44
Filebrowser
fi
else
echo pathselect $1$pathselect
whiptail --title "! ERROR !" --msgbox "Error setting path to image file." 8 44
unset base
unset imgpath
Filebrowser
fi
exit 0
fi
}

Share
Apr 262012
 

I have created an updated version here

I’ve created an update of the Raspberry Pi Memory Split Selector Script that has been cleaned up a bit and functions a bit differently.
The new script can detect the current memory that the system is showing, as well as determining which file has been activated.
Changing the active split will result in the script removing start.elf and copying the relevant elf file to start.elf to enable the new RAM split.
Once again, feedback is most welcome either in this post or in this thread.

The script can be downloaded from here.

Update – a new version has been created from some feedback on the forums, Get it here

Below is the code –

#!/bin/bash
##
## Raspberry Pi Memory Split Selector Script v2
## Author: SirLagz
## Website: http://sirlagz.net
##
## The purpose of this script is to make selecting the memory split
## on the RPi easy.
## Simply make this script executable if it's not already, move
## it to the directory with the elf files, and run it with ./select2.sh
## The menu should be pretty self explanatory.
##
clear
list=./*
b128det=0
b192det=0
b224det=0
bdefdet=0

for i in $list
do
case $i in
"./arm128_start.elf") b128det=1;;
"./arm192_start.elf") b192det=1;;
"./arm224_start.elf") b224det=1;;
"./start.elf") bdefdet=1;;
esac
done

if [[ "$bdefdet" -eq 0 ]] ; then
cp arm192_start.elf start.elf
current=192
fi

if [[ "$b192det" == "$bdefdet" ]] ; then
diffresult=`diff arm192_start.elf start.elf`
if [[ -z $diffresult ]] ; then
current=192
fi
fi

if [[ "$b128det" == "$bdefdet" ]] ; then
diffresult=`diff arm128_start.elf start.elf`
if [[ -z $diffresult ]] ; then
current=128
fi
fi

if [[ "$b224det" == "$bdefdet" ]] ; then
diffresult=`diff arm224_start.elf start.elf`
if [[ -z $diffresult ]] ; then
current=224
fi
fi

declare -i vram
vram=256-$current
sysram=`cat /proc/meminfo | grep MemTotal | awk -F\ '{ printf("%.0f",$2/1024) }'`
echo "##################################"
echo "## Raspberry Pi Memory ##"
echo "## Selector Script ##"
echo "##################################"
echo " Current Memory Split"
echo " CPU $current/$vram VRAM"
echo " Detected System RAM"
echo " $sysram MB"
echo "##################################"
case $current in
128)
echo "1) Set CPU/VRAM split to 192/64"
echo "2) Set CPU/VRAM split to 224/32"
echo "3) Quit"
;;
192)
echo "1) Set CPU/VRAM split to 128/128"
echo "2) Set CPU/VRAM split to 224/32"
echo "3) Quit"
;;
224)
echo "1) Set CPU/VRAM split to 128/128"
echo "2) Set CPU/VRAM split to 192/64"
echo "3) Quit"
;;
*)
echo "Invalid memory detected"
;;
esac
echo "Enter Choice:";
read x

case $x in
1)
case $current in
128)
rm start.elf && cp arm192_start.elf start.elf
;;
192)
rm start.elf && cp arm128_start.elf start.elf
;;
224)
rm start.elf && cp arm128_start.elf start.elf
;;
*)
echo "Invalid memory detected"
;;
esac
;;
2)
case $current in
128)
rm start.elf && cp arm224_start.elf start.elf
;;
192)
rm start.elf && cp arm224_start.elf start.elf
;;
224)
rm start.elf && cp arm192_start.elf start.elf
;;
*)
echo "Invalid memory detected"
;;
esac
;;
3) exit 0;;
esac
if [[ $? -ne 0 ]]; then
echo "Memory Split setting failed"
fi

Share
Apr 202012
 

Update – a newer version has been created here.

With the recent release of the Raspberry Pi, a computer designed to make coding and programming easy, fun, and accessible to children of all ages, there has been some discussion on how to change the memory split between the GPU and CPU.
I have come up with a script to make changing the split easy for all the future programmers who aren’t quite comfortable doing it themselves. I’m not a great coder so if you spot any flaws in this please shout out.

You can download the bash script here.
Feedbask is most welcome as I’m looking to improve the script.

Below is the code for the script itself if you want to copy / paste it instead.
If anyone has any suggestions for the script itself or would like some more options, feel free to express yourself in either the comments section on this port or in this thread


#!/bin/bash
##
## Raspberry Pi Memory Split Selector Script
## Author: SirLagz
## Website: http://sirlagz.net
##
## The purpose of this script is to make selecting the memory split
## on the RPi easy.
## Simply make this script executable if it's not already, move
## it to the directory with the elf files, and run it with ./select.sh
## The menu should be pretty self explanatory.
##
clear
list=./*
b128det=0
b192det=0
b224det=0
bdefdet=0

for i in $list
do
case $i in
"./arm128_start.elf") b128det=1;;
"./arm192_start.elf") b192det=1;;
"./arm224_start.elf") b224det=1;;
"./start.elf") bdefdet=1;;
esac
done

if [[ "$b192det" == "$bdefdet" ]] ; then
diffresult=`diff arm192_start.elf start.elf`
if [[ -z $diffresult ]] ; then
mv arm192_start.elf arm192_start.old.elf
b192det=0
fi
fi

if [[ "$b128det" == "$bdefdet" ]] ; then
diffresult=`diff arm128_start.elf start.elf`
if [[ -z $diffresult ]] ; then
mv arm128_start.elf arm128_start.old.elf
b128det=0
fi
fi

if [[ "$b224det" == "$bdefdet" ]] ; then
diffresult=`diff arm224_start.elf start.elf`
if [[ -z $diffresult ]] ; then
mv arm224_start.elf arm224_start.old.elf
b224det=0
fi
fi

if [[ "$b128det" == 0 ]] ; then
current=128
elif [[ "$b192det" == 0 ]] ; then
current=192
elif [[ "$b224det" == 0 ]] ; then
current=224
fi

declare -i vram
vram=256-$current

echo "##################################"
echo "## Raspberry Pi Memory ##"
echo "## Selector Script ##"
echo "##################################"
echo " Current Memory Split"
echo " CPU $current/$vram VRAM"
echo "##################################"
case $current in
128)
echo "1) Set CPU/VRAM split to 192/64"
echo "2) Set CPU/VRAM split to 224/32"
echo "3) Quit"
;;
192)
echo "1) Set CPU/VRAM split to 128/128"
echo "2) Set CPU/VRAM split to 224/32"
echo "3) Quit"
;;
224)
echo "1) Set CPU/VRAM split to 128/128"
echo "2) Set CPU/VRAM split to 192/64"
echo "3) Quit"
;;
*)
echo "Invalid memory detected"
;;
esac
echo "Enter Choice:";
read x

case $x in
1)
case $current in
128)
mv start.elf arm128_start.elf && mv arm192_start.elf start.elf
;;
192)
mv start.elf arm192_start.elf && mv arm128_start.elf start.elf
;;
224)
mv start.elf arm224_start.elf && mv arm128_start.elf start.elf
;;
*)
echo "Invalid memory detected"
;;
esac
;;
2)
case $current in
128)
mv start.elf arm128_start.elf && mv arm224_start.elf start.elf
;;
192)
mv start.elf arm192_start.elf && mv arm224_start.elf start.elf
;;
224)
mv start.elf arm224_start.elf && mv arm192_start.elf start.elf
;;
*)
echo "Invalid memory detected"
;;
esac
;;
3) exit 0;;
esac
if [[ $? -ne 0 ]]; then
echo "Memory Split setting failed"
fi

Share