Key bind to shutdown pc - i3

I am trying to bind some keys to shutdown the pc instead to write "shutdown now" in terminal.
I have this in my config file to i3:
bindsym $mod+Shift+d exec shutdown now
This piece of code is not working.
Isn't this supposed to write on terminal "shutdown now" when I press mod+shift+d?

try
bindsym $mod+Shift+d exec systemctl poweroff -i
I use this mode
set $mode_system System (l) lock, (e) logout, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
bindsym l exec --no-startup-id $Locker, mode "default"
bindsym e exec --no-startup-id i3-msg exit, mode "default"
bindsym r exec --no-startup-id systemctl reboot, mode "default"
bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+y mode "$mode_system"

Related

Shell script: inject command into existing running terminal process

I have a situation where there is a running terminal process. I can find the PID of the terminal. I want to inject a command s.t. it runs and prints output in the target terminal process. I tried the following:
# Assuming terminal with PID is running in a different window
$ echo "ls\n" > /proc/PID/fd/0
This just prints the string in the second terminal window. How can I send a command (like ls) and then an enter key press into the second terminal window ? Thanks
If you have xdotool installed ;
$ xdotool search --pid 2981 # 2981 being the PID of terminal, not shell
60817444
$ xdotool windowfocus --sync 60817444 type $'ls\n'

Start calcurse upon log in with i3

I am trying to set my i3 configuration file in order to autostart calcurse when I log in.
I have added the line
exec --no-startup-id calcurse
but it doesn't work.
If you want calcurse in an open window on startup, try exec --no-startup-id [xterm/urxvt/whatever_terminal_you_use] -e calcurse. (most terminal use -e to execute a command, check the terminal help if it does not work)
If you want calcurse to run in the background (to get event notifications, and you will still be able to access the interface by executing calcurse in a terminal), go with exec --no-startup-id calcurse --daemon

how to create and move between screens in a bash.sh script [duplicate]

Was wondering how I can start up a command such as:
while :; do ./myCommand; done;
But instead of doing the usual
screen -S nameOfMyScreen
Then the command
while :; do ./myCommand; done;
Then detach the screen
^a ^d (Control "a" the control "d"
I would like it to start and detach. Thanks!
screen -d -m sh -c "while :; do ./myCommand; done;"
Explanation:
-d -m starts screen in detached mode (create session but don't attach to it)
sh -c commandline starts a shell which executes the given command line (necessary, since you are using the while builtin).
From screen -h, these look useful:
-dmS name Start as daemon: Screen session in detached mode.
-X Execute <cmd> as a screen command in the specified session.
I haven't done this myself, but that's where I'd start.
Update:
The top of the help also says
Use: path/to/screen [-opts] [cmd [args]]
so the -X switch may be to execute a screen command as opposed to a shell command. You might just be able to put your command after the -dmS <name> without any -X switch.

Forward Ctrl+C &c. over "ssh -tt" running w/ command from heredoc

I'm trying to have a shell script I can use to do connect somemachine to simplify the following pattern
ssh somemachine
tmux a
I've tried using here docs as Python subprocess with heredocs in order to send "tmux a" command
#!/bin/bash
ssh $1#$2 << 'ENDSSH'
tmux a
ENDSSH
however that fails with "stdin is not a terminal". Following suggestion in Pseudo-terminal will not be allocated because stdin is not a terminal I did following modification
#!/bin/bash
ssh -tt $1#$2 << 'ENDSSH'
tmux a
ENDSSH
But now all my shortcuts are intercepted. IE, CTRL+C will kill my SSH session rather than forwarding SIGINT to the process. Any suggestions?
I think you just need the -t flag and not use the heredoc. Using the heredoc means that the ssh process doesn't have the terminal as its stdin (it has the heredoc instead) so it can't forward it to pseudo-terminal on the remote side. Using the -tt flag forces the pts to be allocated without having an input which means that keypresses go to the local process not the remote one.
#!/bin/bash
ssh $1#$2 -t tmux a
works for me

Network connection lost upon screen remote detach

I'm using secureCRT to ssh to Linux based server.
I use "screen" command to keep my sessions alive.
But things are becoming strange when I using two PC, OK, here's the scene:
On PC-A, start a new screen session named "test";
On PC-B, type screen -D -r test
Hopefully, I'd like to see the 'test' session detached on PC-A, and re-attached to PC-B.
That works, but when PC-A got remotely detached by PC-B, PC-A lost its connection to server.
Just reconnect will be okay, sure, but I'm still want to know why PC-A lost its connection.
Here's the command log of PC-A
[#PC-A ~]$ screen
[remote power detached]
Screen session of test
ended.
Press Ctrl+C to cancel or Enter to reconnect immediately.
Reconnecting in 1 seconds...
Last login: Fri Mar 8 21:16:50 2013 from 10.129.215.167
[#PC-A ~]$ _
And here is my .screenrc file:
#se the startup message
startup_message off
term xterm
##set a biger buffer
defscrollback 4096
#statusbar
hardstatus alwayslastline
shell zsh
shelltitle "$|zsh"
hardstatus alwayslastline "%{=b}%{Y}%-w%{.BW}%10>%n*%t%{-}%+w%< %=%{kG}(F5)New (F6)Kill (F7)Rename (F8)Next %C%A %D, %Y-%m-%d "
vbell off
## w to show the window list
bind w windowlist -b
bind ^w windowlist -b
##initial apps to run
screen
select 0
attrcolor u "-u B"
sessionname test
autodetach off
#shot-key bindings
bindkey -k k5 screen
bindkey -k k6 kill
bindkey -k k7 title
bindkey -k k8 next
screen by default launches with multiuser set to off. That means when a user logs in, it kicks the previous one out. Change that to your .screenrc and you should be fine.
http://linux.die.net/man/1/screen (search for multiuser).

Resources