Page 5 of 6

Posted: Sat 29 Aug 2009, 06:20
by Bruce B
Chapter 92 - a script wanted

Script wanted:

Friends, I've tested the 'proof of concept', the file I'm wanting is easy to make. I'm hoping the readers have been programming and can do this assignment. If you want to work on it, but are embarrassed or not confident, PM me and I'll post it synonymously.

Filenane: checkdiff

Description: using the find command it searches the /parent directories and makes a text database of all files, symlinks and directories in a /parent directory. e.g. /usr and /root

We want to learn about changes in the directory from time to time. We use the find command a second time, merge the two files and pipe the test file to sort | uniq -u.

uniq only works right on a list of sorted files, the uniq -u swich will print only the differences.

Thus we can get a report on files which have been added or deleted.

Fun practical and I have an even more useful similar utility up my sleeve, but I want to see how we do on this.

~

Chapter 92 - a script wanted

Posted: Wed 02 Sep 2009, 22:46
by Bruce B
Chapter 93 assignment submitted

I'm pleased to present anonymously submitted work from chapter 92.

First version

Code: Select all

#!/bin/bash
cd /usr/
# check if a list exists: if not create one and exit.
if
[ ! -e usr-list.cd ]
then echo "Nothing to compare. Creating 'usr-list' then exiting"
find -maxdepth 1 > usr-list.cd && exit
fi

find -maxdepth 1 > usr-list-new.cd
cat usr-list.cd usr-list-new.cd > joined.cd
sort joined.cd | uniq -u
# get rid of the temporary files
rm -f *.cd

exit 
Second version

Code: Select all

#!/bin/bash
# Just realised my basic error
if
[ ! -e list ]
then echo "Nothing to compare. Creating 'list' then exiting"
find -maxdepth 1 > list && exit
fi

find -maxdepth 1 > list-new.cd
cat list list-new.cd > joined.cd
sort joined.cd | uniq -u
rm -f *.cd
exit 


Third version

Code: Select all

#!/bin/bash
# I think I've finally got something a little more sensible:
if
[ ! -e /root/list ]
then echo "Nothing to compare. Creating 'list' then exiting"
find -maxdepth 1 > /root/list && exit
fi

find -maxdepth 1 > /root/list-new
cat /root/list /root/list-new > /root/joined
sort /root/joined | uniq -u
exit

# I just put the temporary files in root, out of the way, 
# and they get overwritten anyway - so no need for 'rm' really. 
Comment: Thanks for the submission. This is exactly how I learn. I write some code. Then, maybe the next day, I conceive a better way or notice a flaw, then refine or even rewrite the code.

In the beginning stages some can learn by lectures, examples and theory. As for me I need to 'code' to develop the skill and confidence.

Thanks again

~

Chapter 93 assignment submitted

Posted: Mon 04 Jan 2010, 05:54
by technosaurus
Simple ldd script to find dependencies - should work on any *nix

Code: Select all

#!/bin/sh
if [ -x $1 ]; then
/lib/ld-linux.so.2 --list $1
else
 if [ -x `which $1` ]; then
 /lib/ld-linux.so.2 --list `which $1`
 else
 echo Can't find it. Try using full path.
 fi
fi
(This one has the comments remove - only 98bytes)

#!/bin/sh
if [ -x $1 ]; then /lib/ld-lsb.so.1 --list $1
else
/lib/ld-lsb.so.1 --list `which $1`
fi

(this one requires the full path - 37 bytes)

#!/bin/sh
/lib/ld-lsb.so.1 --list $1

Posted: Fri 02 Jul 2010, 05:22
by 01micko
hehe

simple word/string finder

Inspired by techno :wink: In living colour :lol:

EDIT: Well I posted this in a separate thread and am maintaining it, the code has progressed from what is below. It mainly demonstrates the use of colours in the CLI. Enjoy! SCLISS

Code: Select all

#!/bin/sh
#01micko (01micko@gmail.com) GPL 2010
#simple command line search script
#syntax "scliss -w" for a word
#"scliss -s" for a string
#"scliss -h" help
#"scliss -v" version
#if you want to colour your bash I got it from "http://edoceo.com/liber/linux-bash-shell"
VER="0.1"
DIR=$2
if [ "$DIR" != "" ];then cd $DIR 2>/dev/null
fi
if [ "$DIR" = "/tmp" ];then
	echo -en "\033[0;35m""Er sorry.. haven't figured out how to handle /tmp yet"  #magenta text
	echo -e "\033[0m"
	exit
fi
if [[ $? -ne 0 ]];then
	echo -en "\033[0;31m""Woops! That's not a directory!"  #red text
	echo -e "\033[0m"
	exit
fi
case $1 in
-w)	echo "type one word you are searching for"
	read SEARCH
	grep $SEARCH *
	;;
-s)	echo "type a string you are searching for"
	read STRING
	grep "${STRING}" *
	;;
-h)	echo "You have invoked scliss help"
	echo "Options"
	echo "	-h prints this help and exits"
	echo ""
	echo "	-v prints version and exits"
	echo ""	
	echo "	-w) type a word to search for in the current directory"
	echo "	and the line(s) where that word resides will be returned for" 
	echo "	every instance it occurs in a line"
	echo "	SYNTAX: scliss -w [/path/to/dir]"
	echo ""
	echo "	-s) type a string to search for in the current directory"
	echo "	and the line(s) where that string resides will be returned for" 
	echo "	every instance it occurs in a line"
	echo "	SYNTAX: scliss -s [/path/to/dir]"
	echo ""
	echo -en "\033[1;33;45m""	the \"/path/to/dir\" is optional"  #yellow text bright, magenta background
	echo -e "\033[0m"
	echo "============================================================"	
	echo -en "\033[0;34m""01micko@gmail.com GPL 2010 NO WARRANTY" #blue text
	echo -e "\033[0m"
	exit
	;;
-v) echo "scliss-${VER}"
	exit
	;;
*)	echo "ERROR: You need an option. Type \"scliss -h\" for more"
	exit
	;;
esac
	if [[ $? -ne 0 ]];then
	echo -en "\033[0;31m""Boo! Not found"  #red text
	echo -e "\033[0m" 
	exit
		else echo -en "\033[0;32m""There you go, found it!"  #green text
		echo -e "\033[0m"
		exit
	fi
Cheers

Posted: Fri 09 Jul 2010, 19:12
by Bruce B
Very good!

Years ago I made simple color changing C source code to use in DOS batch programming.

The basic idea is: it was easier to type in the first three characters of a color than calling a batch file or running the full escape sequence.

If I want text to change to magenta, I enter the command 'mag' then when I want to change the text output again, I enter another color command.

The command itself doesn't insert a line break or change cursor position, it just makes to the text after the command the color I want.

I'm pasting a picture of the C source rather than posting the code as text, because the escape character usually doesn't transfer.

I think it would be very easy to make Linux code by using its escape and color sequences and the printf function.

If you are interested in the project and sharing your work :)

Posted: Sun 11 Jul 2010, 03:16
by technosaurus
Here is one for all the fans of Big Bang Theory, a modified version of Dr. Sheldon Cooper's "Friendship Algorithm" adapted as a bash script.
Image

Code: Select all

#!/bin/sh
person=$1

_partake_(){
	INTERESTS=`Xdialog --stdout --3inputsbox 'Ask '$person' "What are your interests?"' 0 0 "Interest #1" "" "Interest #2" "" "Interest #3" "" |sed "s/\// 0 0 /g" `
	Xdialog --stdout --no-tags --radiolist 'Ask '$person' "What is the least objectionable interest"' 0 0 0 0 $INTERESTS 0
	Xdialog --msgbox "Partake in "$?"." 0 0
	}

_drink_(){
	Xdialog --yesno 'Ask '$person' "Do you enjoy a hot beverage?"' 0 0
	[ $? != 1 ] && BEVERAGE=`Xdialog --stdout --no-tags --radiolist "Which beverage?" 0 0 0 Coffee Coffee 0 Tea Tea 0 \Cocoa Cocoa 0` && Xdialog --msgbox "Have "$BEVERAGE" together" 0 0 || _partake_
#____________________________________________________
	
_dine_(){
Xdialog --stdout --yesno "Place a phone call to "$person".
Did "$person" answer?" 0 0
[ $? == 1 ] && Xdialog --msgbox "Leave "$person" a message and wait for a call back" 0 0
Xdialog  --stdout --yesno 'Ask '$person', "Would you like to share a meal?"' 0 0
[ $? != 1 ] && Xdialog --msgbox "Dine with $person" 0 0 || _drink_
}

_dine_ #? or _drink_ or _partake_ in interest

#....Sheldon says this begins the friendship, but I prefer to do a worthiness evaluation
Xdialog --stdout --yesno "Is "$person" worthy?" 0 0
[ $? == 0 ] && Xdialog --msgbox "Congratulations, "$person" is now your friend" 0 0 && exit
$0 `Xdialog --stdout --inputbox "Unfortunately "$person" is not going to work out as a friend,
Enter the name of another person you would like to be friends with." 0 0`

bash 4.0.10

Posted: Sun 11 Jul 2010, 07:03
by plankenstein
First off let me say this is a great tutorial. Just happened across it and am loving it. But, on the first page you talked about loading a newer version of bash, but the file has been removed. Do you have any plans to put this bash.zip back up or is there some place else I might find it? So far, I'm doing okay following along with the 3.00.16 that came with Dpup, but would like to see how the newer one compares.

Thanks for the hard work that obviously went into this. I've already picked up some new skills and I'm just on chapter 7. This is going to keep me entertained for quite some time to come. :D

Posted: Mon 12 Jul 2010, 21:03
by 01micko
Bruce B wrote:Very good!

Years ago I made simple color changing C source code to use in DOS batch programming.

The basic idea is: it was easier to type in the first three characters of a color than calling a batch file or running the full escape sequence.

If I want text to change to magenta, I enter the command 'mag' then when I want to change the text output again, I enter another color command.

The command itself doesn't insert a line break or change cursor position, it just makes to the text after the command the color I want.

I'm pasting a picture of the C source rather than posting the code as text, because the escape character usually doesn't transfer.

I think it would be very easy to make Linux code by using its escape and color sequences and the printf function.

If you are interested in the project and sharing your work :)
Thanks for the compliment Bruce.

Actually I had already implemented something similar in the latest SCLISS revision. It now reads a config file and any script can actually read that file.
I will post a snippet, its way too large to put it all in one post, but I'll attach the full file. I put it in /etc, which as I understand is a usual place for system
wide settings. I could have made it a hidden file in $HOME too I guess.

Code: Select all

#colors #put together for Puppylinux by 01micko, GPL 2010
#RESULTS MAY NOT be exactly as expected... NO WARRANTY
#Basics
#usual thing is style, fg, bg
#invoke with: echo -en "$COLOR""the text you want" ...where color will be something from the table below (-n is optional)
#stop with: echo -e "$CLEAR_TEXT"
#clear text. This resets the terminal after you have used the colors #ESSENTIAL
CLEAR_TEXT="\033[0m"
#basics
BLACK="\033[0;30m"
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
MAGENTA="\033[0;35m"
CYAN="\033[0;36m"
WHITE="\033[0;37m"
#BOLD
BLACK_B="\033[1;30m"
RED_B="\033[1;31m"
GREEN_B="\033[1;32m"
YELLOW_B="\033[1;33m"
BLUE_B="\033[1;34m"
MAGENTA_B="\033[1;35m"
CYAN_B="\033[1;36m"
WHITE_B="\033[1;37m"
#italics
BLACK_I="\033[3;30m"
RED_I="\033[3;31m"
GREEN_I="\033[3;32m"
YELLOW_I="\033[3;33m"
BLUE_I="\033[3;34m"
MAGENTA_I="\033[3;35m"
CYAN_I="\033[3;36m"
WHITE_I="\033[3;37m"
#underline
BLACK_U="\033[4;30m"
RED_U="\033[4;31m"
GREEN_U="\033[4;32m"
YELLOW_U="\033[4;33m"
BLUE_U="\033[4;34m"
MAGENTA_U="\033[4;35m"
CYAN_U="\033[4;36m"
WHITE_U="\033[4;37m"
#COLORED BACKGROUNDS
#WHITE	#GOOD FOR BLACK TERMINAL
BLACK_WBG="\033[0;30;47m"
RED_WBG="\033[0;31;47m"
GREEN_WBG="\033[0;32;47m"
YELLOW_WBG="\033[0;33;47m"
BLUE_WBG="\033[0;34;47m"
MAGENTA_WBG="\033[0;35;47m"
CYAN_WBG="\033[0;36;47m"
WHITE_WBG="\033[0;37;47m"
#(SNIP) see attachment
It also deals with bold, italics and underline as well as coloured backgrounds. I think I covered the lot, well enough anyway!

Cheers

Posted: Fri 16 Jul 2010, 02:57
by technosaurus

Code: Select all

#!/bin/sh
echo Direct Dependencies: && objdump -x $1 |grep NEEDED |sed "s/NEEDED//g" |sed "s/ //g"
I call this one lddd because it only lists the direct dependencies

For instance: if you link against X11, regular ldd will also list libXau, libxdmcp and others because they are a dependency of X11

this may only be useful for someone building a small/embedded distro around proprietary software like skype, opera and flashplugin etc... but maybe other uses?

this can tell you if it is possible to statically link a dependent library directly into the shared library that is actually linked against ... or maybe even configure the shared library that is linked against without the unused libs if possible - you'd be surprised how many are really unnecessary

.gz

Posted: Fri 13 Aug 2010, 06:25
by Frank Cox
could you tell me the commands if the bash comes as a tar.gz.gz?

Posted: Fri 13 Aug 2010, 13:06
by technosaurus
gunzip *
gunzip *
tar -xf *

(you probably don't need the 2nd gunzip)

Posted: Sun 22 Aug 2010, 20:16
by technosaurus
Here is a little script I wrote to download and allow older versions of flash to work on websites that require a newer version unnecessarily (by faking the version number)
Flash7 will work on non-gtk2 browsers
Flash9 is smaller, has much fewer dependencies (no mozilla libs) and is still being updated (for enterprise linux distros)
Flash10.X default is to install the latest version in case of a site that actually requires features that are only in 10.x.

Code: Select all

#!/bin/sh
case $1 in
--help)echo "options are:
7 for smallest size and dependencies,
9 for medium size and fewer dependencies
  for latest version leave options blank"
;; 

#download all flash7 & fake latest as 10.1 r9
7)wget -c http://fpdownload.macromedia.com/get/flashplayer/installers/archive/fp7_archive.zip
unzip fp7_archive.zip
tar -xf fp7_archive/r73/install_flash_player_7_linux_r73.tar.gz
cat install_flash_player_7_linux/libflashplayer.so |sed -e "s/7.0 r73/10.1 r9/g" >/usr/lib/mozilla/plugins/libflashplayer.so
rm -rf fp7_archive.zip install_flash_player_7_linux_r73.tar.gz install_flash_player_7_linux fp7_archive
yaf-splash -text "flash7 installed as flash10.1" -transparent -bg red -timeout 10
;;

#download latest flash9 & fake install as 10.1 r99
9)wget -c http://download.macromedia.com/pub/flashplayer/installers/current/9/install_flash_player_9.tar.gz
tar -xf install_flash_player_9.tar.gz
VER=`strings libflashplayer.so | grep -e "^Shockwave Flash [.\d+]*" | sed -e "s/Shockwave Flash //g"`
cat libflashplayer.so |sed -e "s/$VER/10.1 r99/g" >/usr/lib/mozilla/plugins/libflashplayer.so
rm -f libflashplayer.so install_flash_player_9.tar.gz
yaf-splash -text "flash9 installed as flash10.1" -transparent -bg red -timeout 10
;;

#download and install latest flash
*)wget -c http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz
tar -xf install_flash_player_10_linux.tar.gz
mv -f libflashplayer.so /usr/lib/mozilla/plugins/libflashplayer.so
rm -f install_flash_player_10_linux.tar.gz
yaf-splash -text "latest flash installed" -transparent -bg red -timeout 10
;;
esac
exit

Posted: Tue 28 Sep 2010, 16:57
by ds2dys
Wow! :shock:

This was my only word came out from my mouth when I clicked through page numbers to find over 90 chapters.
This is amazing lecture for people who want to learn about Linux like me. I'm going to start from the Chapter 1 now.

Thank you very much for sharing this valuable knowledge.

:D :D :D

Posted: Tue 07 Jun 2011, 08:51
by eriksatie
ds2dys wrote:Wow! :shock:

This was my only word came out from my mouth when I clicked through page numbers to find over 90 chapters.
This is amazing lecture for people who want to learn about Linux like me. I'm going to start from the Chapter 1 now.

Thank you very much for sharing this valuable knowledge.

:D :D :D
I would like to second this notion. I'm still on the first page, but I will be making my way to the rest of the chapters in due time.

Thank you so much for taking the time to teach us linux newbies the TUI!

8)

Thanks

Posted: Sat 03 Sep 2011, 21:49
by Superdooper
Thanks for the tutorial! Wow im amazed some one took the time to write this up. Hopefully you will get the time to continue the series. Thanks again! :D

Excellent source of help!

Posted: Fri 02 Dec 2011, 13:03
by MrDurtal
Thanks very much for all of the effort.

MrDurtal

Posted: Wed 08 Feb 2012, 09:05
by rhadon
Hi,

I have a general question. I can write

Code: Select all

if ...condition...;then
   do this...
fi
if not...condition...;then
   do that...
fi
or I can write

Code: Select all

if ...condition...;then
   do this...
else
   do that...
fi
It looks to me that the last one is 'better style' but is it really better, maybe faster?

Concrete example, with slacko 5.3.2.1 in rcsysinit, ~line 754 is written:

Code: Select all

#save button on desktop when booted from flash drive...
if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ];then #pup_rw is tmpfs.
 if [ "`cat /root/Choices/ROX-Filer/PuppyPin | grep "save2flash"`" = "" ];then
  echo '<icon x="768" y="128" label="save">/usr/sbin/save2flash</icon>' >> /root/Choices/ROX-Filer/PuppyPin
  cat /root/Choices/ROX-Filer/PuppyPin | grep -v '/pinboard' > /tmp/PuppyPin-CPY
  sync
  cp -f /tmp/PuppyPin-CPY /root/Choices/ROX-Filer/PuppyPin
  echo '</pinboard>' >> /root/Choices/ROX-Filer/PuppyPin
 fi
fi
I added:

Code: Select all

if ! [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ];then #pup_rw is tmpfs.
 if ! [ "`cat /root/Choices/ROX-Filer/PuppyPin | grep "save2flash"`" = "" ];then
	cat /root/Choices/ROX-Filer/PuppyPin | grep -v "^<icon x=\"768\" y=\"128\" label=\"save\"" >/tmp/PuppyPin-CPY
	cp -f /tmp/PuppyPin-CPY /root/Choices/ROX-Filer/PuppyPin
	echo '</pinboard>' >> /root/Choices/ROX-Filer/PuppyPin
 fi
fi
Is it worth to change?

Thanks,
Rolf

Posted: Wed 08 Feb 2012, 09:35
by 01micko
Hi Rolf..
Is it worth to change?
Probably yes!

But it's embedded in woof and getting upstream changes like that are difficult as there are always more pressing issues.

[One example is how gdk-pixbuf-query-loaders is run since gtk+2.20 , I tried to get Barry to change it to the correct call from what I researched but to no avail, I patch it every time I build slacko]

I would do it completely differently...

Code: Select all

case $PUPMODE in
3|7|13)
(code for whatever goes here)
;;
*)echo
;;
esac
:)

Posted: Wed 08 Feb 2012, 12:43
by rhadon
Thanks Mick :D

I wasn't aware about '*)' in case...esac. Will give it a try.

I also know that it's only for one special version. If woof changes (I know it does often :lol: ), everything must be done again and maybe it doesn't work in newer versions or at least it must be changed. Too annoying to do it everytime. But a good feeling to be able to do so and it works. That's the fun. :lol:

Cheers
Rolf

Posted: Fri 30 Mar 2012, 03:35
by SkullyRipz
Bruce...

... thank you. :D This is exactly what I needed. I appreciate all the time spent. Its very well put together and easy to follow.