[英]How to redirect the output of the time command to a file in Linux?
[英]In Linux, how to redirect wall output in script to file?
我正在嘗試使用以下行在bash腳本中記錄事件:
#!/bin/bash
{
...
echo "Photo backup successfully finished on $(date)" | wall
...
} &>> "/var/log/$(basename "$0").log" &
但是,在日志文件中,相應的行顯示為:
wall: cannot get tty name: Inappropriate ioctl for device
似乎牆輸出無法定向到文件。
我怎樣才能讓它發揮作用? (能夠發布到牆上並將消息記錄到文件中)
一種可能性是使用“tee -a”而不是“>>”。 例如:
echo "Hello world"|tee -a myfile.log|wall
似乎只是因為當前終端擁有其他用戶/組而不是你運行sommand。 以下在Fedora 21中測試的示例。
檢查與“w”一樣使用的TTY
$ w
09:20:21 up 10:34, 2 users, load average: 0.22, 0.27, 0.35
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
alex pts/0 08:38 41:17 0.27s 13.46s /usr/bin/xfce4-terminal
alex pts/1 08:39 5.00s 0.81s 13.46s /usr/bin/xfce4-terminal
接着
$ ls -l /dev/pts/*
total 0
crw--w----. 1 alex tty 136, 0 Mar 13 09:18 0
crw--w----. 1 alex tty 136, 1 Mar 13 09:22 1
然后你可以添加應該向牆發送消息的用戶,將“tty”分組
mcedit /etc/group
...
tty:alex,nut
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.