![]() |
Helloやアメリカ合衆国へようこそ! UNIXおよびLinuxフォーラム!訪問し、当社のグローバルコミュニティに参加いただきありがとうございます。
|
|
Googleのunix.com
|
|||||||
| シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。 |
その他のUNIXおよびLinuxフォーラムトピックは参考にすること
|
||||
| スレッド | スレッドスターター | フォーラム | 返信 | 最後の投稿 |
| 場合は、スクリプトを手動で起動されているかどうかを決定するか? | hitmansilentass | シェルプログラミングとスクリプティング | 8 | 2008年6月22日 12:32午後 |
| SFTPの上で実行時には手動で実行するcronは1 errorcode | Heidi.Ebbs | Sun Solaris | 2 | 2007年8月8日 01:16午後 |
| Unixシェルスクリプトでは、誰もチェックを手動でスクリプトを実行することができます | adi_bang76 | シェルプログラミングとスクリプティング | 1 | 2006年11月16日 10:43午前 |
| 作品手動-いないのCRONで | dstinsman | UNIXのダミー質問と回答のため | 5 | 2006年3月6日 08:36午前 |
| 手動ではないのcronからスクリプトを実行することはできますか? | MadHatter | シェルプログラミングとスクリプティング | 4 | 2005年10月19日 11:08午前 |
![]() |
|
|
LinkBack | スレッドツール | このスレッドを検索 | スレッドを評価 | 表示モード |
|
|
|
||||
|
cronから対手動でスクリプトを実行するときに異なる動作を
やあ、すべて、
ちょうど私は、 MySQLデータベースを使用しているファイルをインポートするには、スクリプトにいくつかの入力を取得している。 このプロセスは非常に簡単です:私のメインサーバーの輸出は、これらのファイルとFTPS彼ら。私は、スクリプトがあるFTPs彼らに、マシンでは、このスクリプトを実行している。スクリプトは、 FTPまたは手動たびはcronからbith問題がなく実行されます。 この問題は、 cronは、以下のスクリプトを実行する場合に発生します。ごされるよう、これらの私の最初のスクリプトがあります。 ![]() ループが、素晴らしいのは初めてのポイントは、 mysqlimportは再度実行すると呼ばれていますに死ぬときにループを再び。最初のファイルは、正常に動作website_tabProperty.txtこの場合。これで死ぬwebsite_tabBuilding.txt 。 私のcronは、 rootとしてこのスクリプトを実行するように設定されています。 私は手動で"このスクリプトを実行されている。 / "に長い時間のたびに動作します。 私は、ループとはcronとの問題の図が、私は何をするカント。 ご協力いただきありがとうございます。 勘定 コード:
#!/bin/bash
echo "Starting new batch import `date`"
echo "Starting new batch import `date`" >> /root/import.log
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Imporatnt: The last file and table in these arrays MUST be the data that is targeted for
#the append operation.
#define the files names for import and existance verification. These are renamed to the names below
file_name[1]=/root/website_tabProperty.txt
file_name[2]=/root/website_tabBuilding.txt
file_name[3]=/root/website_tabApartment.txt
file_name[4]=/root/website_tabMeters.txt
file_name[5]=/root/website_tabReadings.txt
#define the file names for importation. The file names must match the table names
target_file_name[1]=/root/tabProperty.txt
target_file_name[2]=/root/tabBuilding.txt
target_file_name[3]=/root/tabApartment.txt
target_file_name[4]=/root/tabMeters.txt
target_file_name[5]=/root/tabReadings.txt
#define the target tables to flush
target_table[1]=tabProperty
target_table[2]=tabBuilding
target_table[3]=tabApartment
target_table[4]=tabMeters
target_table[5]=tabReadings
#this number nust be one higher than the max index in the arrays.
MAX_LOOP=6
#Set this value to the index we want to append - will force it to skip the flush
APPEND_INDEX=5
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#set the file name suffix for the renaming routine
suffix=`date +%m_%d_%Y`
COUNTER=1
while [ $COUNTER -lt $MAX_LOOP ]; do
echo "---------------------------------------"
echo "---------------------------------------" >> /root/import.log
echo "Processing index - "$COUNTER
echo "Processing index - "$COUNTER >> /root/import.log
DIR=${file_name[COUNTER]}
if [ -f $DIR ];then
echo "Original "${file_name[COUNTER]}" exists"
echo "Original "${file_name[COUNTER]}" exists" >> /root/import.log
echo "Renaming "${file_name[COUNTER]}
echo "Renaming "${file_name[COUNTER]} >> /root/import.log
cp ${file_name[COUNTER]} ${target_file_name[COUNTER]}
echo "Removing "${file_name[COUNTER]}
echo "Removing "${file_name[COUNTER]} >> /root/import.log
rm ${file_name[COUNTER]}
#Only flush the table if it is not the last one in the index
if [ $COUNTER != $APPEND_INDEX ]; then
echo "Flushing "${target_table[COUNTER]}
echo "Flushing "${target_table[COUNTER]} >> /root/import.log
mysql -u root -p8895asdf7665553 -e "use wellspring; delete from "${target_table[COUNTER]}";"
sleep 2
else
echo "Not Flushing "${target_table[COUNTER]}
echo "Not Flushing "${target_table[COUNTER]} >> /root/import.log
fi
echo "Importing "${target_file_name[COUNTER]}
echo "Importing "${target_file_name[COUNTER]} >> /root/import.log
mysqlimport -u root -p8895asdf7665553 --local wellspring ${target_file_name[COUNTER]}
sleep 2
echo "Renaming "${target_file_name[COUNTER]}
echo "Renaming "${target_file_name[COUNTER]} >> /root/import.log
cp ${target_file_name[COUNTER]} ${target_file_name[COUNTER]}.$suffix
sleep 1
echo "Removing "${target_file_name[COUNTER]}
echo "Removing "${target_file_name[COUNTER]} >> /root/import.log
rm ${target_file_name[COUNTER]}
sleep 1
else
echo "Original "${file_name[COUNTER]}" does not exist"
echo "Original "${file_name[COUNTER]}" does not exist" >> /root/import.log
fi
let COUNTER=COUNTER+1
done
echo "---------------------------------------"
echo "---------------------------------------" >> /root/import.log
echo "Finished batch import `date`"
echo "Finished batch import `date`" >> /root/import.log
echo "*********************************************************************************"
echo "*********************************************************************************" >> /root/import.log
exit
|
|
||||
|
引用:
---私と検索を使用するように提案を高く評価はどうすればよいのリンクを誰にするか-がどのように環境、特にスクリプトの影響に関する具体的な情報の大きな額ではありませんでした。私は誰か、この分野での経験があるかもしれないバニラを使用してさらにポイントが私の方向に(つまり-期待していたもの)対やっていた私は、上記に関係なく実行されます。 ところで、私は子供のころ、 1時間ごとに私のC64をプレイするためのニッケルZaxxonだったなあ。 |