Translate with Google Translate

10.01.2011

Sh Cheat Sheet

#File:ShCheatSheet.sh v.1.1.0 docs at the end 
#source:http://www.dartmouth.edu/~rc/classes/ksh/index.html#for loop example
for file in * ; do echo Processing $file ; done ; 
 
for file in  `ls -1` ; do echo Processing $file ; done ; 
 
#if example 
 
if [ -r $myfile ]
then
   cat $myfile
else
   echo $myfile not readable
fi
 
#case example 
 
case $filename in
*.dat)
echo Processing a .dat file
;;
*.sas)
echo Processing a .sas file
;;
*)
# catch anything else that doesn't match patterns
echo "Don't know how to deal with $filename"
;;
esac
 
 
*
Matches any zero or more characters. 
?
Matches any one character. 
[string]
Matches exactly one character that is a member of the string string. This is called a character class. As a shorthand, string may contain ranges, which consist of two characters with a dash between them. For example, the class ‘[a-z0-9_]’ matches a lowercase letter, a number, or an underscore. You can negate a class by placing a ‘!’ or ‘^’ immediately after the opening bracket. Thus, ‘[^A-Z@]’ matches any character except an uppercase letter or an at sign. 
\
Removes the special meaning of the character that follows it. This works even in character classes.
 
# while example 
count=0
max=10
while [[ $count -lt $max ]] ; do 
  echo $count ; 
  count=$((count + 1)) ; 
done ; 
echo "Value of count after loop is: $count"
 
 
 
wlog(){
        echo "`date +%Y.%m.%d-%H:%M:%S` [$$] $*" >> $LOGFILE
        test -t 1 && echo "$*"
}
 
send_mail(){
        # $1 = subject
        # $* = recipients
        # - = text
        test -z "$2" && {
                wlog "NOTICE: no mail recipients"
                return 0
        }
        _sm_s="$1"
        shift 1
        mailx -s "$_sm_s" $* || {
                wlog "ERROR: Failed to send mail to $*"
                return 1
        }
        return 0
}
 
#get a nice date
`date +%Y%m%d%H%M%S`
 
outgoing_dirs=`find $ROOTDIR -type d -name 'outgoing'`
 
for odir in $outgoing_dirs
do
        test -d "$odir" || continue
        find $odir -type f -mtime $MAXAGE -print0 | xargs --null -r $debug rm
done
 
#The ultimate find in files 
DirToSearch=/var/log/
FilesToSearch=`ls -rt $DirToSearch`
for file in $FilesToSearch
do
        file=$DirToSearch/$file
        test -f "$file" || continue 
        grep -nH 'sekauppi' $file  
done
 
 
find $DirToSearch -type f -exec grep -nH 'yogeorgi' {} \; | less 
 
today=`date +%Y%m%d`
yesterday=`date --date yesterday +%Y%m%d`
 
Help(){
        cat<<EOF
 
`basename $0` [-t filetype] [-f srcfile] [-o outfile] [-D outdir]
        [-u owner] [-g group] [-U srcurl] [-d day -d day2 ...]
        [-F] [-b daysback]
 
        filetype:       {userlist | auditlog}
        user:           $channel_user
        srcurl:         $BASE_URL
        daysback:       $DAYS_BACK
 
        -F to force download even if file was downloaded already
EOF
 
#Purpose: 
# Provide an easy copy paste resource for sh programming
# VersionHistory: 
# 1.1.0 --- ysg --- Updated docs , published 
# 1.0.0 --- ysg --- Initial version , see main source 

0 comments:

Post a Comment

- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!

Blog Archive

My Blog List

Labels

perl (23) how-to (16) sql server 2008 (12) cmd windows batch (10) mssql (10) sql server 2005 (8) textpad (8) windows (8) Cheat Sheet (7) Unix (7) code generation (7) meta data mssql (7) metadata (7) excel (5) linux (5) tsql (5) utilities (5) energy (4) future (4) programs (4) settings (4) поуки (4) принципи (4) Focus Fusion (3) Solaris (3) cmd (3) cool programs (3) cygwin (3) economy (3) freeware (3) fusion (3) html (3) morphus (3) mssql 2005 (3) nuclear (3) parse (3) perl modules (3) script (3) shortcuts (3) sofware development (3) table (3) .Net (2) C# (2) China (2) Solaris Unix (2) ascii (2) cas (2) cheatsheet (2) columns (2) duplicates (2) example (2) file (2) free programs (2) generic (2) google code (2) logging (2) mssql 2008 (2) mysql (2) next big future (2) nsis (2) prediction (2) release management (2) security (2) sftp (2) sql (2) sqlserver 2005 (2) sqlserver 2008 (2) ssh (2) template (2) tools (2) vba (2) youtube videos (2) BSD license (1) Bulgaria (1) Dallas (1) Database role (1) Dense plasma focus (1) Deployment (1) ERP (1) ExcelToHtml (1) GDP (1) GUI (1) Google (1) GoogleCL (1) Hosting (1) IT general (1) IZarc (1) Java Web Start (1) Khan Academy (1) ListBox (1) MIT HYDROGEN VIRUS (1) OO (1) PowerShell (1) Run-time (1) SIWA (1) Services (1) Stacks (1) SubSonic (1) TED (1) abstractions (1) apache (1) apache 2.2 (1) application life cycle (1) architecture (1) archive (1) arguments (1) avatar (1) awk (1) backup (1) bash (1) bin (1) biofuels (1) biology (1) books (1) browser (1) bubblesort (1) byte (1) cas_sql_dev (1) chennai (1) class (1) claut (1) code generation sqlserver (1) command (1) command line (1) conf (1) configuration (1) console (1) conversion (1) copy-paste (1) csv (1) ctags (1) current local time (1) data (1) debt (1) diagram (1) digital (1) documentation (1) dos (1) dubai (1) e-cars (1) electric cars (1) electricity (1) errors (1) exponents (1) export (1) extract (1) fast export (1) fexp (1) findtag (1) firewall (1) for loop (1) functions (1) fusion research (1) german (1) helsinki (1) history (1) hop or flop (1) ideas (1) java (1) ksh (1) level (1) london (1) me (1) metacolumn (1) metadata functions (1) metaphonre (1) method (1) model (1) movie (1) n900 (1) nano (1) netezza (1) non-password (1) nord pol (1) one-to-many (1) open source (1) openrowset (1) outlook (1) parser (1) password (1) permissions (1) php (1) platform (1) ppm (1) predictions (1) prices (1) principles (1) project (1) prompt (1) proxy account (1) public private key (1) publish (1) publishing (1) putty (1) qt (1) read file (1) registry (1) relationship (1) rm (1) scp (1) sed (1) sh (1) silicon (1) sofware (1) sort (1) sql script (1) sql_dev (1) sqlcmd (1) sqlite (1) sqlite3 (1) src (1) sshd (1) stored procedure (1) stupidity (1) svn (1) sysinternals (1) tar (1) temp table (1) templates (1) teradata (1) terminal (1) test (1) theory (1) thorium (1) time (1) tip (1) tool (1) user (1) utils (1) vb (1) warsaw (1) wikipedia (1) windows programs (1) windows reinstall (1) wisdoms (1) worth-reading (1) xp_cmdshell (1) youtube (1)

Video Bar

Loading...

Search This Blog

Loading...