yum -y install wget
yum -y install readline-devel
yum -y install libXt-devel
yum -y install gcc gcc-c++
yum -y install gcc-gfortran
yum -y install libg2c.so.0
yum -y install less
yum -y install bzip2-devel
yum -y install zlib-devel
yum -y install xz-devel.x86_64
yum -y install make
yum -y install zip unzip
mkdir /download
cd /download
wget -c http://www.cpan.org/src/5.0/perl-5.26.1.tar.gz
tar -xvzf perl-5.26.1.tar.gz
cd /download/perl-5.26.1
sh Configure -de
make
make test
make install
(4) 执行shell脚本
bash myinstall.sh > myinstall.log # Standard output to a log file
bash myinstall.sh >& myinstall.log # Log both Standard output and Standard error
bash myinstall.sh > myinstall.log 2> myinstall.err # Log STDOUT and STDERR separately
Example II
backup files using rsync and crontab
(0) install rsync and crontab
yum -y install rsync
yum -y install crontabs
mkdir /mac/backup # prepare the backup dir
(1) Prepare a backup script, for example, "~/backup.sh"
#!/bin/bash
#1. Local backup
RSYNC="rsync --stats --compress --recursive --times --perms --links --delete --max-size=100M --exclude-from=/home/john/.rsync/exclude"
echo "1. Backup of /home/john start at:"
date
$RSYNC /home/john/data/ /mac/backup/
echo "Backup end at:"
date
#2. Remote backup
RSYNC="rsync --stats --compress --recursive --times --perms --links --delete --max-size=100M"
echo "2. Backup 172.22.220.20:/data/ to /mac/backup2/ start at:"
date
$RSYNC john@172.22.220.20:/home/john/data/ /mac/backup2/
echo "Backup end at:"
date
(2) Using "crontab" command to execute the backup script routinely, and record in a log file, for example,
execute the command "~/backup.sh > ~/backup.log" in 5:10am everyday:
chmod +x ~/backup.sh
1) open crontab and edit it by the following command:
crontab -e or crontab ~/cronjob
2) type in the following lines or write the following in a file (i.e. ~/crontab):
# minute hour day_in_month month day_in_week command
10 5 * * * ~/backup.sh > ~/backup.log
3) exit and save (like in VIM)
3) Tips
awk
gawk '{print $2 $1}' FILE | head -100
cat FILE | gawk '(NR>2) {print }'
gawk -f FILE # take command from file
Begin { a=1; ORS = " "} # ORS: output record seperator
...
input STANDIN in your script
rnatotal.o <<EOF
trna.lis
trna.out
trna
EOF
grep non ATGC nucleotides in fasta file
grep -v "^>" test.fasta | \ # ^ means start with here
grep --color -i "[^ATCG]" # ^ means non- here
A tee in your pipe
program1 input.txt | tee intermediate-file.txt | program2 > results.txt
Exit Status
program1 input.txt > inter.txt && \ # run program 2 only if program1 is success (i.e. exit status is 0: $? = 0)
program2 inter.txt> results.txt
program1 input.txt > inter.txt || \
echo "warning: an error occurred
Name dir with today's date
mkdir results-$(date +F%) # +F% format is 2018-03-18
alias today="date +F%" # you can put this in ~/.bashrc
mkdir results-$(today)