同样的问题在a question posted to the Unix & Linux StackExchange community更好的制定。代码在Shell脚本运行之前其他操作
我编程,其在按键打开了一个脚本,打开一个新的终端(GNOME终端),运行scrot(截图工具),可以用如下随机名称的图片目录,上传它pomf。 cat并将链接复制到剪贴板。
这工作正常。现在我想要做的是上传完成后关闭终端。
我的脚本是这样工作的:
快捷方式(PrtScr) - >的gnome-terminal -e “蟒蛇路径/到/ script.py” - >启动Scrot - >保存文件(记住文件路径) - > bash script2.sh path/to/picture - >上传到pomf.cat - >获取链接 - >通过“xclip -selection剪贴板”放入剪贴板
因为我想在关闭终端后把字符串到剪贴板,我补充说:
eval $(printf $link | xclip -selection clipboard && sleep 1 && pkill terminal)
这个问题是,没有被复制到C唇膏和终端关闭。
然而,如果没有“& &睡眠1 & & pkill的终端”的链接被复制,但在终端保持打开状态。
在此先感谢。
//编辑
的第一个Script(运行scrot)
#!/usr/bin/env python
import os
import uuid
import time
def rstring(string_length=10):
random = str(uuid.uuid4())
random = random.upper()
random = random.replace("-","")
return random[0:string_length]
randomString = rstring(16)
os.system("scrot -s -q 100 /home/timon/screenshots/" + randomString + ".jpg")
while True:
processRead = os.popen("ps aux | grep \"scrot -s\" | cat").read()
if "scrot -s" not in processRead:
time.sleep(1)
else:
break
system.sleep(3)
os.system("/home/timon/.screenshot_stuff/./screen.sh /home/timon/screenshots/" + randomString + ".jpg")
第二个脚本(上传截图)
#!/usr/bin/env bash
dest_url='https://cuntflaps.me/upload.php'
return_url='https://a.cuntflaps.me'
if [[ -n "${1}" ]]; then
file="${1}"
if [ -f "${file}" ]; then
printf "Uploading ${file}..."
my_output=$(curl --silent -sf -F files[]="@${file}" "${dest_url}")
n=0 # Multipe tries
while [[ $n -le 3 ]]; do
printf "try #${n}...\n"
if [[ true ]]; then
return_file=$(echo "$my_output" | grep "url" | sed 's/\,//g' | sed 's/\\//g' | sed 's/\"//g' | sed 's/\url://g' | tr -d ' ')
printf 'done.\n'
break
else
printf 'failed.\n'
((n = n +1))
fi
done
printf "$return_file" | xclip -selection clipboard && pkill terminal
else
printf 'Error! File does not exist!\n'
exit 1
fi
else
printf 'Error! You must supply a filename to upload!\n'
exit 1
fi
为什么你需要'eval'? – Leon
这是用于运行命令,不是吗? –
不完全是,它是为了增加额外的扩展/替代水平,这似乎是不需要你的情况。事实上,它甚至被错误地使用 - 它会尝试以'$(...)'命令的输出命令的形式运行。 – Leon