Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在脚本运行时更改重定向路径_Bash_Shell_Solaris 10 - Fatal编程技术网

Bash 在脚本运行时更改重定向路径

Bash 在脚本运行时更改重定向路径,bash,shell,solaris-10,Bash,Shell,Solaris 10,我有一个bash脚本,它总是在我将其重定向到文件的位置提供输出,我尝试做的是旋转重定向的文件,下面是我启动原始脚本并重定向它的位置: . somecode . su - username -c "command >> /path/to/directory/output.txt" & . . code continues.. 下面是我试图创建的crontab: cd /path/to/directory/ timestamp=`date "+%Y%m%d"` mv .

我有一个bash脚本,它总是在我将其重定向到文件的位置提供输出,我尝试做的是旋转重定向的文件,下面是我启动原始脚本并重定向它的位置:

.
somecode
.    
su - username -c "command >> /path/to/directory/output.txt" &
.
.
code continues..
下面是我试图创建的crontab:

cd /path/to/directory/
timestamp=`date "+%Y%m%d"`
mv ./output.txt ./logs/output.txt_$timestamp
touch output.txt
chmod 757 ./output.txt
gzip ./logs/output.txt_$timestamp
find ./logs/output.txt* -type f -mtime +2 | xargs rm
或者这个人也没能完成任务:

timestamp=`date "+%Y%m%d"`
cp ./output.txt ./logs/output.txt_$timestamp
echo "" > ./output.txt
gzip ./logs/output.txt_$timestamp
在第一个代码中,原始脚本失败并且不再工作,而在第二个脚本中,它没有清理output.txt文件

有没有办法在保持脚本正常工作的同时做到这一点?注;我正在运行Unix Solaris


提前感谢。

您可以使用以下命令

su - username -c "command >> /path/to/directory/output`date "+%Y%m%d"`.txt" &
或者这可能对你有帮助

它有logrotate吗?没有。我能找到的唯一解决方案是停止所有脚本,然后在启动脚本后进行旋转。如果有办法在运行时更改输出路径,效果会更好,但即使这样做,因为它是脚本,如果出现故障,也会发送短信,因此,10分钟的停机时间,同时轮换仍然是可以接受的。谢谢大家的帮助