該腳本是先刪除已經存在的文件,然後後台執行SQL語句將其執行結果以一定的格式寫入文件
#!/bin/bash if [ -f "/var/lib/mysql/hell.txt" ]; then rm -f /var/lib/mysql/hell.txt echo "delete /var/lib/mysql/hell.txt" >> hell.txt fi mysql -uroot -plab <<EOF use home; select YongHuID,XueYuanID into outfile './hell.txt' fields terminated by '|' lines terminated by '\r\n' from sns_home_user where YongHuID < 20; EOF