Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
On Windows I use this file bat that allows me to start the artisan application without having to do everything manually every time
cd c:\xampp\htdocs\gamelite-lv
php artisan serve
I tried to replicate the script for Mac, but I can't use it:
#!/bin/bash
cd ..
cd ..
cd Applications
cd mamp
cd htdocs/lv/
php artisan serve
moreover, with the batch for mac, is it possible to create a system of choices like?
#ECHO OFF
:StartLoop
CLS
ECHO 1.Start Laravel
ECHO 2.Update Composer
ECHO 3.Install Composer
ECHO 4.Show Router
ECHO 5.Run SASS
ECHO.
CHOICE /C 12345 /M "Select choice:
I solved that:
PS3='Choise: '
options=("Start Laravel" "Update Composer")
select opt in "${options[#]}"
do
case $opt in
"Start Laravel")
cd /applications/mamp/htdocs/lv
php artisan serve
;;
"Update Composer")
cd /applications/mamp/htdocs/lv
php composer.phar update
;;
*) echo "$REPLY invalid choice";;
esac
done
In order to start the file with a double click I renamed the .command file, and I set the permissions:
chmod ugo+x file
Related
Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 months ago.
Improve this question
Xrdp server on kali linux. Also there is installed freerdp2-shadow-x11 to start the shadow session.
The shadow server is started with the freerdp-shadow-cli command in the terminal of a running xrdp session. And only so.Interactively on the command line with output.
I need it to run in the background from autoload along with the session of the user connected to the server.
Partially, I solved it with a script:
#!/bin/bash
freerdp-shadow-cli -auth -port:3389 -may-interact > /dev/null 2>&1 &
interactively, this script is executed and everything works, but if you add it to autoload (.zshrc file), then the script will only run when you open the terminal with your hands.
And so, experts, the question is:
How can I make the script autoload?
Finally figured it out myself
From the very beginning:
apt install freerdp2-shadow-x11
nano /home/user/RDS.sh
RDS.sh:
#!/bin/bash
#gnome-terminal -e
freerdp-shadow-cli -auth -port:3389 -may-interact > /dev/null
2>&1 &
cli:
chmod 755 RDS.sh
nano /home/user/.config/autostart/shadow.desktop
shadow.desktop:
[Desktop Entry]
Name=shadow
GenericName=A descriptive name
Comment=Some description about your script
Exec=/home/user/RDS.sh
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true
cli:
chmod 755 shadow.desktop
reboot
-may-interact -only show desktop
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to write a script that will create a new user on a linux (ubuntu) server. I'm new to script writing, I'm having problems on
how to read variables from the user input and using that variable in other parts of the script
This is sort of what I have, but getting stuck in the execution of it. Thanks.
update_pkgs() {
echo "
----------------------
Prerequisites : Making sure everything is up to date
----------------------
"
# checks is all pkgs are up to date
sudo apt-get update -y
# installing necessary pkgs
sudo apt-get install build-essential libssl-dev -y
}
create_user() {
echo "
----------------------
1. Creating a new user with name `<user>` and gives correct access.
----------------------
"
# [ASK]: How to make <user> a variable I read from STDIN
# and pass it around in the following commands
# add new user with the name of `user`
sudo adduser --ingroup www-data --disabled-password <user>
# copy ssh/ folder from `ubuntu` user to new user
# and gives the right permissions/privileges
sudo cp -R .ssh/ /home/<user>/
sudo chown -R <user>:www-data /home/<user>/.ssh/
}
# 1. asks to run the script
echo "
----------------------
Do You Wish to run this Script ?
----------------------
"
select yn in "Yes" "No" create quit; do
case $yn in
Yes)
update_pkgs();
create_user();
break;;
No) exit;;
create)
read -p "Enter name of user: " user
create_user($user)
quit)
break;;
*)
echo 'Invalid option $REPLY'
esac
done
bash always runs commands in order, unless you tell it to run the command in the background.
You can see how to save the stdin to a variable here.
You should make the question more focused. As regards the request in the title (How to get input from STDIN and save it in a variable in bash), it is too generic too.
The answer depends on what you expect to be given from stdin (One word? One line? More lines?), what do you plan to do with it (read in a "scalar" variable, or in an array?), and other factors.
For instance, executing the following in the terminal is enough to read a line from stdin to a a variable named var:
read var
But you want something more for sure.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to run sudo with my password as parameter so that I can use it for a script. I tried
sudo -S mypassword execute_command
but without any success. Any suggestions?
The -S switch makes sudo read the password from STDIN. This means you can do
echo mypassword | sudo -S command
to pass the password to sudo
However, the suggestions by others that do not involve passing the password as part of a command such as checking if the user is root are probably much better ideas for security reasons
You can set the s bit for your script so that it does not need sudo and runs as root (and you do not need to write your root password in the script):
sudo chmod +s myscript
echo -e "YOURPASSWORD\n" | sudo -S yourcommand
One option is to use the -A flag to sudo. This runs a program to ask for the password. Rather than ask, you could have a script that just spits out the password so the program can continue.
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to run sudo with my password as parameter so that I can use it for a script. I tried
sudo -S mypassword execute_command
but without any success. Any suggestions?
The -S switch makes sudo read the password from STDIN. This means you can do
echo mypassword | sudo -S command
to pass the password to sudo
However, the suggestions by others that do not involve passing the password as part of a command such as checking if the user is root are probably much better ideas for security reasons
You can set the s bit for your script so that it does not need sudo and runs as root (and you do not need to write your root password in the script):
sudo chmod +s myscript
echo -e "YOURPASSWORD\n" | sudo -S yourcommand
One option is to use the -A flag to sudo. This runs a program to ask for the password. Rather than ask, you could have a script that just spits out the password so the program can continue.
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a little problem with the i3 tiling window manager's ~/.i3/config file.
I am trying to set the pm-suspend utility as a key-binding of Mod4 (the windows key) + p (the p char).
I have this bash script called suspendandlock in /usr/bin/:
#!/bin/bash
sudo pm-suspend | i3lock -i /home/antony/unity-desk.png -p default -d -n
I previously modified the /etc/sudoers file with visudo, adding this line:
%users ALL = NOPASSWD: /usr/sbin/pm-suspend
So that no one needs the password to execute pm-suspend utility.
Then I have my i3 config file, where I added this:
bindsym $mod+p exec suspendandlock
Where $mod is the Mod4 key.
The script works fine from gnome-terminal when I type the suspendandlock command -> it suspends the system and blocks the screen as expected.
But when I type Mod4+p from keyboard it only blocks the screen without executing pm-suspend.
Why does it not work?
Does anyone knows where I am wrong?
It looks like OP solved the problem, but for anyone else who needed to fix it (myself included), just run:
sudo usermod -aG users `whoami`
which pm-suspend || sudo apt-get install pm-utils #make sure you have pm-suspend command, install it if you don't
run sudo visudo and add:
%users ALL = NOPASSWD: /usr/sbin/pm-suspend
and then add:
bindsym $mod+p exec "sudo pm-suspend | i3lock"
to ~/.i3/config. Running $mod+p will now lock and then suspend your computer.