Linux Reference6.1 Shell, bash |
20.02.2008 |
| ← 6 System Administration | [ up ] - [ top ] - [ linux a-z ] | 6.1.1 ~/.bashrc → |
Transform variables
Transform "foo.txt" into "foo.html"#!/bin/bash myvar="foo.txt" newvar=`echo $myvar | sed 's/\.txt/\.html/'` echo "before = $myvar" echo "new = $newvar"
Shell Loops
#!/bin/bash # -- works with /bin/sh as well :-) for yourvar in foo bar more do echo "- $yourvar" done
MySQL Backup Script
#!/bin/bash DBNAME=dbboard echo `/bin/date` # YYYYMMDD: mydate=`date +%Y%m%d` mkdir /var/lib/mysql/$DBNAME/$mydate-all echo -n "DB Dump all ... " /usr/bin/mysqldump -u root $DBNAME >/var/lib/mysql/$DBNAME/$mydate-all/$DBNAME.dump echo -n "done at " echo `/bin/date` cd /var/lib/mysql/$DBNAME /bin/tar -czf /var/lib/mysql/$DBNAME/$mydate-all.tar.gz $mydate-all /bin/rm -Rf /var/lib/mysql/$DBNAME/$mydate-all ls -lt /var/lib/mysql/$DBNAME/*.tar.gz
Exit, if a specific process is running
#!/bin/bash if [ `/usr/local/bin/getpid yourprocess.pl` ]; then echo "Better luck next time" exit 0 fi echo "Continuing..." echo "DELETE FROM foo" |psql -d bar
See also:
- html-ify → /perl/auto htmlify
- Subsignal.org/doc/AliensBashTutorial.html
- Reference
Big bash tutorial
subsignal.org/doc/AliensBashTutorial.html
- fnal.gov/docs/products/bash/bashref.html - Reference
Reference Documentation for Bash
fnal.gov/docs/products/bash/bashref.html
copyright by retoh - created with mytexi