我試圖從一個文件夾移動一個非常具體的命名文件到另一個(最終被SFTP'd到另一臺服務器)。KSH腳本將文件移動到SFTP文件夾
的文件名應該是這樣的: reports_aug_30.csv
用我現在的劇本,我有問題,得到它在該格式。我得到: aug_30_reports.csv
我想要做的是在開始處移動日期,然後讓它保留文件名的其餘部分的名稱。
有沒有人有如何格式化報告名稱的建議?
在我的腳本中的兩個相關的功能是:
function REPORTS
{
# specify SFTP report path
SFTPDIR=/home/josh/domain/sftp/reports
[email protected]
CHKSFTP
typeset -l FILEDR=$tmp
typeset -l FILENM=reports.csv
typeset -l MIXFNM=$FILEDR/$FILENM
typeset -l NEWFILENM
if [[ -f $MIXFNM ]]
then
ls -al $MIXFNM | awk '{print $6,$7}' | while read MONTH DAY
do
NEWFILENM=$FILENM_${MONTH}_${DAY}
echo "---------------------------------------------"
echo "[ `date` ]"
echo "** $FNCTN file located on `hostname` ! **"
echo "moving: $MIXFNM to $SFTPDIR/$NEWFILENM"
mv $MIXFNM $SFTPDIR/$NEWFILENM
done
else
echo "---------------------------------------------"
# echo -e "[ `date` ] - No files with a name of $FILENM located in $FILEDR were found on [ `hostname` ] - Please check the respective operations for failures" | mailx -s "$FNCTN File not found [ `hostname` ]!" $ALERT_LIST
echo "[ `date` ]"
echo -e "WARNING: No files with a name of $FILENM located in $FILEDR were found on [ `hostname` ]! \n Email alert sent to $ALERT_LIST"
fi
}
function CHKSFTP
{
## check for the SFTP directory before we continue, if it fails then we exit with failure
if [[ ! -d $SFTPDIR ]]
then
echo "Please Mount the CIFS share /home/josh/domain/sftp/reports" | mailx -s "SFTP Share Not Mounted [ `hostname` ]!" $ALERT_LIST
exit 1
fi
}
在將來,您不需要發佈如此大的代碼塊。以最簡單的形式顯示問題,包括樣本輸入,預期輸出,代碼,當前輸出以及您爲什麼使用當前代碼的意見。另外,使用'[ksh]'標籤來關注Q的讀者。祝你好運。 – shellter