STNYLug Meeting Notes from 12-23-2003
How to check current shell
$ echo $SHELL #works on 1st SHLVL
/bin/bash
$ tcsh
> echo $SHELL #doesn't work for subshells
/bin/bash
> ps #seems to work accurately
PID TTY TIME CMD
7288 pts/4 00:00:00 bash
18297 pts/4 00:00:01 emacs
27112 pts/4 00:00:00 tcsh
27113 pts/4 00:00:00 ps
> chsh # doesn't work
Password:
Changing the login shell for mightyd
Enter the new value, or press return for the default
Login Shell [/bin/bash]:
Using the type command to find commands
$ type eval
eval is a shell builtin
$ type ls
ls is /bin/ls
$ type lhead
lhead is a function
lhead ()
{
lynx -head -dump http://$1
}
What to do if ls is gone
$ echo /usr/local/*
/usr/local/RealPlayer8 /usr/local/bin /usr/local/games /usr/local/include
/usr/local/lib /usr/local/man /usr/local/sbin /usr/local/share
/usr/local/src
On-the-fly shell scripts
$ ls *.gz
alien_8.41.tar.gz apsfilter-7.2.5.tar.gz
nagios-plugins-1.4.0alpha1.tar.gz
$ tar xzvf *.gz #tar doesn't take multiple args.
tar: apsfilter-7.2.5.tar.gz: Not found in archive
tar: nagios-plugins-1.4.0alpha1.tar.gz: Not found in archive
tar: Error exit delayed from previous errors
$ for file in *.gz #this works
> do
> tar xzvf $file
> done
$ find . -iname '*.gz' -exec tar xzvf '{}' ';' #This works, too.
Cowsay
$ cowsay -f sodomized I Love Linux.
_______________
< I Love Linux. >
---------------
\ _
\ (_)
\ ^__^ / \
\ (oo)\_____/_\ \
(__)\ ) /
||----w ((
|| ||>>
More scripting
$ i=100; while [ $i > 0 ]; do echo $i; let i=i-1 ; done #didn't work
100
99
[snip]
0
-1
[infinite]
$ i=100; while [[ $i > 0 ]]; do echo $i; let i=i-1 ; done #works because:
$ help [
[: [ arg... ]
This is a synonym for the "test" builtin [...]
$ help test
test: test [expr]
Exits with a status of 0 (true) or 1 (false) depending on
the evaluation of EXPR [...]
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
$ help [[
[[ ... ]]: [[ expression ]]
Returns a status of 0 or 1 depending on the evaluation of the
conditional expression EXPRESSION. [...]
So basically, '[' is good for string comparisons like '-gt'.
'[[' is good for arithmetic expressions like '>'.
More shell scripts/loops
$ for ( i=0; i < 100; i++ ); do echo $i; done #didn't work
$ for (( i=0; i < 100; i++ )); do echo $i; done #worked because:
$ help for
[snip]
for ((: for (( exp1; exp2; exp3 )); do COMMANDS; done
[snip][..needed two parenthesis.]
Checked a snort log and inspected some netbios info
[excerpt from log..]
2.92 5 XXX.XX.XXX.XXX MS-SQL Worm propagation attempt
[/excerpt]
$ nmblookup -A XXX.XX.XXX.XXX
Looking up status of XXX.XX.XXX.XXX
DUYDD1 <00> - B <ACTIVE>
SCH <00> - <GROUP> B <ACTIVE>
DUYDD1 <03> - B <ACTIVE>
DUYDD1 <20> - B <ACTIVE>
BLUE <03> - B <ACTIVE>
$ smbclient -I XXX.XX.XXX.XXX -L DUYDD1 -U administrator -W SCH
Password:
Anonymous login successful
Sharename Type Comment
--------- ---- -------
Error returning browse list: NT_STATUS_ACCESS_DENIED
Anonymous login successful
[snip]
[We could get 'anonymous logins' but every PC we checked had a password.]
Wasn't that fun?
-Dan