我正在一個腳本刪除所有打印機的工作年齡超過一天,沒有工作年長超過一天必須是打印也已取消了作業ID如何在bash shell中使用導出?
下面是我必須遵循
幾個條件我無法訪問cups目錄,我無法創建任何臨時文件。 我必須使用Bash shell。
我試圖使用一個變量,聲明外循環while但變量值保持不變〜才知道這是因爲子進程 試圖使用導出變量,但也不能在Bash shell中工作,同樣工作在ksh shell中。
我曾嘗試以下邏輯:
count=0
currDate=`date +%Y%m%d`
lpstat -o|while read line
do
jobid=`echo $line|awk '{print $1}'|cut -d"-" -f2`
jobDate=`echo $line|awk -F ' ' 'BEGIN{OFS="-";} {print $5,$6,$7;}'`
formattedDate=`date -d"${jobDate}" +%Y%m%d`
if [ `expr $currDate - $formattedDate` -gt 1 ]
then
count=`expr $count + 1`
echo " cancelling printer job with jobid $jobid "
cancel $jobid
fi;
done
[ $count -gt 0 ] ; echo "NO of Printer jobs pending more than 1 days are $count";
沒有得到如何處理計數變量作爲上述方式將無法正常工作, 出口是不是在bash shell中工作,創建tmp文件是不允許的。
任何建議獲得解決方案。
有沒有執行命令,並得到awk命令循環 內導致像我將得到格式化的日期任何可能的方式並嘗試在awk循環內處理 – Learner
不要使用'expr';使用Bash內置算法'$((...))'(和'((...))')。 –