当前位置: 技术问答>linux和unix
在crontab 里面运行的脚本,没执行压缩gzip 什么原因啊
来源: 互联网 发布时间:2016-07-10
本文导语: 各位大虾: 小弟跪求解答, hp 的unix,在crontab 头运行的脚本,,明明写了,压缩,但就是没压缩。。。。不晓得什么原因。 路径也用的绝对路径。。 下面,是一个我写的脚本,,实...
各位大虾:
小弟跪求解答,
hp 的unix,在crontab 头运行的脚本,,明明写了,压缩,但就是没压缩。。。。不晓得什么原因。
路径也用的绝对路径。。
下面,是一个我写的脚本,,实现功能是 ,压缩文件后,自动移走到当天的目录。
#/bin/ksh
TZ=CST+16
export TZ
ToDay=`date +%Y%m%d`
today=`date +%y%m%d`
month=`date +%Y%m`
TZ=CST-8
export TZ
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_2/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_3/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_4/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_5/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_6/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_7/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_8/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_9/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_2/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_3/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_4/$month/$ToDay/
mkdir -p /raw1/gsm_eric_Tju/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_zte/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_cro/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_cbo/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_cio/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_zte_2g/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw2/gprs_egcdr_3g/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprs_scdr_3g/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprs_egcdr_3g_hw/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/hwsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/intersms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/telsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/ptpsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/ltzxsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprsmms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/vpn/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/vac/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_cc08/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_204_221_230/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_basecall_pre/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_basecall_af/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_400_800/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_lan/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/voip/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/xuanling/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/zengzhi/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/zengzhi17/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/sp/rawcdr_bak/$month/$ToDay/
bak_path1="/raw1/gsm_eric/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path2="/raw1/gsm_eric/rawcdr_bak/MSC_2/$month/$ToDay/"
bak_path3="/raw1/gsm_eric/rawcdr_bak/MSC_3/$month/$ToDay/"
bak_path4="/raw1/gsm_eric/rawcdr_bak/MSC_4/$month/$ToDay/"
bak_path5="/raw1/gsm_eric/rawcdr_bak/MSC_5/$month/$ToDay/"
bak_path6="/raw1/gsm_eric/rawcdr_bak/MSC_6/$month/$ToDay/"
bak_path7="/raw1/gsm_eric/rawcdr_bak/MSC_7/$month/$ToDay/"
bak_path8="/raw1/gsm_eric/rawcdr_bak/MSC_8/$month/$ToDay/"
bak_path9="/raw1/gsm_eric/rawcdr_bak/MSC_9/$month/$ToDay/"
bak_path10="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path11="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_2/$month/$ToDay/"
bak_path12="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_3/$month/$ToDay/"
bak_path13="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_4/$month/$ToDay/"
bak_path14="/raw1/gsm_eric_Tju/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path15="/raw1/gsm_zte/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path16="/raw1/gsm_cro/rawcdr_bak/$month/$ToDay/"
bak_path17="/raw1/gsm_cbo/rawcdr_bak/$month/$ToDay/"
bak_path18="/raw1/gsm_cio/rawcdr_bak/$month/$ToDay/"
bak_path19="/raw1/gsm_zte_2g/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path20="/raw2/gprs_egcdr_3g/rawcdr_bak/$month/$ToDay/"
bak_path21="/raw2/gprs_scdr_3g/rawcdr_bak/$month/$ToDay/"
bak_path22="/raw2/gprs_egcdr_3g_hw/rawcdr_bak/$month/$ToDay/"
bak_path23="/raw2/hwsms/rawcdr_bak/$month/$ToDay/"
bak_path24="/raw2/intersms/rawcdr_bak/$month/$ToDay/"
bak_path25="/raw2/telsms/rawcdr_bak/$month/$ToDay/"
bak_path26="/raw2/ptpsms/rawcdr_bak/$month/$ToDay/"
bak_path27="/raw2/ltzxsms/rawcdr_bak/$month/$ToDay/"
bak_path28="/raw2/gprsmms/rawcdr_bak/$month/$ToDay/"
bak_path29="/raw1/vpn/rawcdr_bak/$month/$ToDay/"
bak_path30="/raw2/vac/rawcdr_bak/$month/$ToDay/"
bak_path31="/raw2/gw_cc08/rawcdr_bak/$month/$ToDay/"
bak_path32="/raw2/gw_204_221_230/rawcdr_bak/$month/$ToDay/"
bak_path33="/raw2/gw_basecall_pre/rawcdr_bak/$month/$ToDay/"
bak_path34="/raw2/gw_basecall_af/rawcdr_bak/$month/$ToDay/"
bak_path35="/raw2/gw_400_800/rawcdr_bak/$month/$ToDay/"
bak_path36="/raw2/gw_lan/rawcdr_bak/$month/$ToDay/"
bak_path37="/raw2/voip/rawcdr_bak/$month/$ToDay/"
bak_path38="/bill2/xuanling/rawcdr_bak/$month/$ToDay/"
bak_path39="/bill2/zengzhi/rawcdr_bak/$month/$ToDay/"
bak_path40="/bill2/zengzhi17/rawcdr_bak/$month/$ToDay/"
bak_path41="/bill2/sp/rawcdr_bak/$month/$ToDay/"
#if ps -ef|grep $bak_path1 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_1/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_1/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path1 >/dev/null
done
#fi
#if ps -ef|grep $bak_path2 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_2/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_2/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path2 >/dev/null
done
#fi
#if ps -ef|grep $bak_path3 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_3/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_3/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path3 >/dev/null
done
#fi
#if ps -ef|grep $bak_path4 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_4/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_4/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path4 >/dev/null
done
#fi
小弟跪求解答,
hp 的unix,在crontab 头运行的脚本,,明明写了,压缩,但就是没压缩。。。。不晓得什么原因。
路径也用的绝对路径。。
下面,是一个我写的脚本,,实现功能是 ,压缩文件后,自动移走到当天的目录。
#/bin/ksh
TZ=CST+16
export TZ
ToDay=`date +%Y%m%d`
today=`date +%y%m%d`
month=`date +%Y%m`
TZ=CST-8
export TZ
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_2/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_3/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_4/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_5/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_6/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_7/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_8/$month/$ToDay/
mkdir -p /raw1/gsm_eric/rawcdr_bak/MSC_9/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_2/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_3/$month/$ToDay/
mkdir -p /raw1/gsm_hw_gtg/rawcdr_bak/MSC_4/$month/$ToDay/
mkdir -p /raw1/gsm_eric_Tju/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_zte/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw1/gsm_cro/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_cbo/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_cio/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/gsm_zte_2g/rawcdr_bak/MSC_1/$month/$ToDay/
mkdir -p /raw2/gprs_egcdr_3g/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprs_scdr_3g/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprs_egcdr_3g_hw/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/hwsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/intersms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/telsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/ptpsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/ltzxsms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gprsmms/rawcdr_bak/$month/$ToDay/
mkdir -p /raw1/vpn/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/vac/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_cc08/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_204_221_230/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_basecall_pre/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_basecall_af/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_400_800/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/gw_lan/rawcdr_bak/$month/$ToDay/
mkdir -p /raw2/voip/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/xuanling/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/zengzhi/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/zengzhi17/rawcdr_bak/$month/$ToDay/
mkdir -p /bill2/sp/rawcdr_bak/$month/$ToDay/
bak_path1="/raw1/gsm_eric/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path2="/raw1/gsm_eric/rawcdr_bak/MSC_2/$month/$ToDay/"
bak_path3="/raw1/gsm_eric/rawcdr_bak/MSC_3/$month/$ToDay/"
bak_path4="/raw1/gsm_eric/rawcdr_bak/MSC_4/$month/$ToDay/"
bak_path5="/raw1/gsm_eric/rawcdr_bak/MSC_5/$month/$ToDay/"
bak_path6="/raw1/gsm_eric/rawcdr_bak/MSC_6/$month/$ToDay/"
bak_path7="/raw1/gsm_eric/rawcdr_bak/MSC_7/$month/$ToDay/"
bak_path8="/raw1/gsm_eric/rawcdr_bak/MSC_8/$month/$ToDay/"
bak_path9="/raw1/gsm_eric/rawcdr_bak/MSC_9/$month/$ToDay/"
bak_path10="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path11="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_2/$month/$ToDay/"
bak_path12="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_3/$month/$ToDay/"
bak_path13="/raw1/gsm_hw_gtg/rawcdr_bak/MSC_4/$month/$ToDay/"
bak_path14="/raw1/gsm_eric_Tju/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path15="/raw1/gsm_zte/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path16="/raw1/gsm_cro/rawcdr_bak/$month/$ToDay/"
bak_path17="/raw1/gsm_cbo/rawcdr_bak/$month/$ToDay/"
bak_path18="/raw1/gsm_cio/rawcdr_bak/$month/$ToDay/"
bak_path19="/raw1/gsm_zte_2g/rawcdr_bak/MSC_1/$month/$ToDay/"
bak_path20="/raw2/gprs_egcdr_3g/rawcdr_bak/$month/$ToDay/"
bak_path21="/raw2/gprs_scdr_3g/rawcdr_bak/$month/$ToDay/"
bak_path22="/raw2/gprs_egcdr_3g_hw/rawcdr_bak/$month/$ToDay/"
bak_path23="/raw2/hwsms/rawcdr_bak/$month/$ToDay/"
bak_path24="/raw2/intersms/rawcdr_bak/$month/$ToDay/"
bak_path25="/raw2/telsms/rawcdr_bak/$month/$ToDay/"
bak_path26="/raw2/ptpsms/rawcdr_bak/$month/$ToDay/"
bak_path27="/raw2/ltzxsms/rawcdr_bak/$month/$ToDay/"
bak_path28="/raw2/gprsmms/rawcdr_bak/$month/$ToDay/"
bak_path29="/raw1/vpn/rawcdr_bak/$month/$ToDay/"
bak_path30="/raw2/vac/rawcdr_bak/$month/$ToDay/"
bak_path31="/raw2/gw_cc08/rawcdr_bak/$month/$ToDay/"
bak_path32="/raw2/gw_204_221_230/rawcdr_bak/$month/$ToDay/"
bak_path33="/raw2/gw_basecall_pre/rawcdr_bak/$month/$ToDay/"
bak_path34="/raw2/gw_basecall_af/rawcdr_bak/$month/$ToDay/"
bak_path35="/raw2/gw_400_800/rawcdr_bak/$month/$ToDay/"
bak_path36="/raw2/gw_lan/rawcdr_bak/$month/$ToDay/"
bak_path37="/raw2/voip/rawcdr_bak/$month/$ToDay/"
bak_path38="/bill2/xuanling/rawcdr_bak/$month/$ToDay/"
bak_path39="/bill2/zengzhi/rawcdr_bak/$month/$ToDay/"
bak_path40="/bill2/zengzhi17/rawcdr_bak/$month/$ToDay/"
bak_path41="/bill2/sp/rawcdr_bak/$month/$ToDay/"
#if ps -ef|grep $bak_path1 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_1/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_1/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path1 >/dev/null
done
#fi
#if ps -ef|grep $bak_path2 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_2/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_2/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path2 >/dev/null
done
#fi
#if ps -ef|grep $bak_path3 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_3/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_3/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path3 >/dev/null
done
#fi
#if ps -ef|grep $bak_path4 |grep -v grep |grep -v vi|grep -v more |grep -v tail
#then
#echo "moving file" > /raw1/log/caijibak.log
#else
echo "start module: move bak_file" >> /raw1/log/caijibak.log
cd /raw1/gsm_eric/rawcdr_bak/MSC_4/
gzip /raw1/gsm_eric/rawcdr_bak/MSC_4/*
file=`ls $today*`
for i in $file
do
mv $i $bak_path4 >/dev/null
done
#fi
|
你先用/usr/contrib/bin/gzip来压缩一个文件测试一下
|
crontab 运行 shell 与 手工运行最大的不同就环境不同,
如果你的 shell 手工运行能工作, 那肯定就是环境问题了。
最常见的就是PATH问题。
你把你的命令的路径全带上,,
如果你的 shell 手工运行能工作, 那肯定就是环境问题了。
最常见的就是PATH问题。
你把你的命令的路径全带上,,