I am using a shell script to automatically search network access points, and in airodump you use ctrl + c to stop the search, and I am wanting to it cancel the search but keep my shell script running. Since I am wanting to do user input after I am done searching for wifi networks. I tried to use trap, and it stops airodump, and my script.
I am just wanting to stop airodump wifi search and move onto my shell script of user input.
It's not entirely clear to me, but I believe you are wanting the user to be able to interactively stop the search via ctrl-C and then be prompted for input. This should do that:
#!/bin/sh
trap 'test "$airo" && kill -2 $airo' 2
airodump ... &
airo=$!
wait
unset airo
# Commands here will execute after the user hits ctrl-C to terminate the search
Related
I'd like to run a remote bash shell that is fully interactive.
The client side should be able to send commands to this bash process and get the outputs interactively.
This means that, just like in a local bash prompt, the correlation between commands and their respected responses isn't necessarily guaranteed, since we may get outputs from a previous command that runs in the background, after running another command.
It works when I run separate bash process and use pipes:
bash 2>&1 | tee file
bash > file 2>&1
However, if I need to send control characters like Tab for auto-completion or Ctrl+C, in case we want to terminate the current command.
It may sound similar to SSH protocol, but I'd like to experiment with this option of running an alternative remote shell, with different access control and UI experience.
So, my question is: How do I pass the control character to the remote bash process (for example, the auto-completion) and get back the results (for example, list of choices for auto-completion)?
NOTE: I don't wish to develop bash equivalent shell script, but just build a proxy process that is able to pass both data and control characters and provide seamless bash experience as in local /ssh mode.
I want to use some scripts to stop and start a bunch of programs, each running in a separate linux screen. These programs run continuously and need to be stopped using Ctrl-C.
So I can write some code to stop a screen:
screen -S "mysessionname" -X quit
but do I need to send a Ctrl-C somehow first of all and if so then how?
Also, I can start a new detached screen thus from within a script:
screen -mdS "mysesssionname"
but how can I then kick of the job from within this screen using a script? I've tried attaching to the session and then starting the job all from within a script but it doesn't seem to work
Well let's hope that this can help you but to simulate the Ctrl-C in a script as far as i know you can use something like kill -3 and the pid of the process. See in manual of signals: "man 7 signal"
I have a script that runs a program that generates an email and then waits for the user to input information from that email. Because of this, the information is not available to pipe to the program on execution. It has to be done after it's running already.
I've tried a number of the different method suggestions, redirecting to the terminal (echo or cat > /dev/pts/#), mkfifo, expect, etc. Most of these methods are successful in actually sending the information to the target terminal - I actually see the information show up there. But there doesn't seem to be a way to send the equivalent of someone pressing the enter key.
Newline (using echo -en) or \n inside of the information send actually makes the cursor move in the target terminal - but it's not the same as actually pressing enter. It just scrolls the screen down one line. If I select the terminal window and press enter, it then accepts the input.
How can I do this from a different terminal (or can I?)
Or better yet, is there a way from the same script that's launched the program now waiting for input to send the program input?
Most of what I've seen has gone the route of using another terminal to try to send the information to the program.
Flow:
Simple similar example is if you were running a shell script that during its execution, runs a program that generates a PIN sent to your email, and then waits for the PIN to be entered before continuing.
In terminal 1, a bash script is run - one of the steps this script does is launch a program that generates an email and then sits at a prompt, waiting for the user to provide input (data from the email sent).
In terminal 2 (or if you can do this through terminal 1 somehow), take the value from the email and input it to the program in terminal 1, including pressing the enter key, so the program sees this value as actually entered and the program can complete its execution.
script in terminal 1:
...
if [ -f $progamToRun ]; then
$programToRun # This program sends the email and prompts the user for information from the email. It waits here...
# once information from email is entered, continue executing commands here
fi
script in terminal 2:
...
# monitor email
# retrieve information from email
# send information to program in terminal 1 that is waiting for this input
# exit script
The steps for the script in terminal 2 are working - and all of the methods I've tried to send the information to the program in terminal 1 haven't worked - that is to say, even if the information appears in the terminal through STDIN, etc. the application running doesn't recognize it as input so it's still sitting in the wait state.
I attempted to use netcat as suggested, but that's failing differently.
In terminal 1 I ran:
cat /tmp/nctest | /tmp/docl.sh -i 2>&1 | nc -l 127.0.0.1 8080 > /tmp/nctest
docl.sh contains one line, the application I am running to generate the email and wait.
In terminal 2 I ran:
nc 127.0.0.1 8080 <information from email>
When I run this in terminal 2, I immediately get the error from the program run in the script in terminal 1 that it failed. I tried this:
nc 127.0.0.1 8080
by itself to see if there was an issue passing the information on the same line I run nc, but get the same result. It's like the first terminal's nc command actually runs the application and then somehow bypasses or processes the prompt, so it's gone before I can enter the information from the email.
I also tried the command in terminal 1 without the -i and without the 2>&1, but there was no difference in the result.
When I log onto my assorted PCs I usually have a number of things I want to happen automatically, but not always straight away.
These include starting terminal sessions in specific locations on specific desktops (because you get used to using the same layout) and those terminal sessions performing specific acts such as ssh commands. However sometimes when you logon after a reboot you may not want to execute those commands immediately as a higher priority action may need your attention first.
So....what I want is my login script to open terminal sessions and have the session commands pre populated on the command line, but not yet executed.
I use Mate and Compiz as my DE as I like its flexibility.
So in my login script I currently have commands such as.....
mate-terminal --window-with-profile=default --geometry=85x24+180+400 --title='SSH1' &
mate-terminal --window-with-profile=default --geometry=85x24+180+1080 --title='VNC1' &
mate-terminal --window-with-profile=default --geometry=85x24+1305+400 --title='SSH2' &
mate-terminal --window-with-profile=default --geometry=85x24+1305+1080 --title='VNC2' &
These are dedicated mate-terminal sessions that I then enter a ssh and vnc command respectively to connect to some remote boxes. They always open in the same workspace and as can be seen open at a specific location so I always know exactly where I expect them to be.
However I don't want to use the option to say have the ssh command built into the script (as ssh is time sensitive to the receiver and I may not get to it straight away), instead I want to have the command already pre populated in the terminal session so when I do get to it I don't have to type in the whole command each time.
I had looked at using expect to do this and have that working thus
#!/usr/bin/expect -f
# Get a bash shell
spawn -noecho bash
# wait for a prompt
expect ">:"
# type something
send "ssh root#192.168.1.1"
# Hand over control
interact
exit
however I can't see a way of using expect that allows me to spawn the mate-terminal session at specific geometry locations (possibly I'm missing something obvious as I haven't used expect before).
I also don't want to autologon to the ssh sessions using something like a bash 'mate-terminal -c' option as at times the machine may not be network connected which means I'll have a load of potentially messed up attempted connects.
So in recap.
Bash login script.
Opens mate-terminal session at specific geometry locations with command line pre populated with desired command but not yet executed.
Ideas?
I created a database and a table inside it.I insert records manually and then run a python script which reads the records and updates them in the table. I was just trying
the make &>1.txt command to redirect the output when the unexpected happened.
Even when I am not running the script and insert the record manually from mysql, the script is
running somewhere as it updates the records , but I am not running it any tab
What is the reason ??
The script just starts running by itself!!!
If it's running in the background (which could have happened if you typed make & >1.txt with a space, not what you showed above) then the jobs command will show it is running, and fg will bring it to the foregound, so you can kill it with Ctrl-C
(You can also kill it with the jobspec shown by jobs e.g. kill %1 but if you don't know what you're doing it's simpler to bring it to the foreground and interrupt it)