英文:
How to run a shell command inside a pod in the background?
问题
我正在尝试在我的Pod中运行AWS CLI命令。由于Pod可能需要一些时间才能完成,我试图在后台运行它。
以下是我的命令:
kubectl -it exec <podname> -- bash -c "aws s3api list-objects --bucket bucketname-1 --query 'Contents[?StorageClass==\"ONEZONE_IA\"].[Key,StorageClass]' --output text > /storage/ONEZONE_keys1.txt &"
当我运行这个命令时,它变成了一个僵尸进程(defunct process)。
当我在命令末尾去掉&
时,它可以正常工作,但一旦关闭终端,进程就会被终止。
最终,我只想每天将这个命令作为cron作业运行。
不确定出了什么问题,或者整个过程是否可以更好地完成。
非常感谢任何帮助,谢谢。
英文:
I am trying to run an AWS CLI command in my pod. As the pod may take some time to complete i am trying to run it in the background
Here is my command
kubectl -it exec <podname> -- bash -c "aws s3api list-objects --bucket bucketname-1 --query 'Contents[?StorageClass==\"ONEZONE_IA\"].[Key,StorageClass]' --output text > /storage/ONEZONE_keys1.txt &"
when I run this command it becomes a defunct process
when I run the command without the &
in the end it works fine
But the process gets terminated once the terminal is closed
Ultimately I just want to run this command as a cron job every day
Not sure whats wrong ,or this whole process can be done in a better way
Any help is much appreciated, Thank you
答案1
得分: 2
我认为nohup可以在这种情况下帮助。尝试使用"nohup"执行此命令。
示例:
nohup "your command" > "redirect file-name" &
英文:
I think nohup can help on this scenario. Try to execute this command with "nohup".
Ex-
> nohup "your command" > "redirect file-name" &
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论