I want to run a python script in a tmux session on startup when launching my google cloud vm. I have searched around stack overflow and found this piece of code.
#! /bin/bash
sudo -H -u MyUser tmux new-session -d -s discord 'python3 MyFile.py'
I placed this in the meta data part of my vm where startup_scripts go but it doesn't launch when i start my vm. However when I run this code in the terminal after my vm has started it does exactly what I want it to do. What am I missing here?
After digging around for I while I found the problem. The command runs in the root directory so, before your piece of code, you have to add:
Add: cd home/username
Before your code.
I'm trying to install anaconda in my own docker container with a bash script. The problem is there's a license agreement that you need to hold down a key to agree to, and the length of which depends on your terminal window size. Is there any way to get around this so that I can run Anaconda3-5.1.0-Linux-x86_64.sh from start to finish from another bash script?
I tried echo "\n\n\n\n\n\n\n" | ./Anaconda3-5.1.0-Linux-x86_64.sh, but this only works when the installer asks for an Enter key press the very first time.
bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -p $HOME/anaconda3
-b — Batch mode with no PATH modifications to ~/.bashrc. Assumes that you agree to the license agreement. Does not edit the .bashrc or .bash_profile files.
-p — Installation prefix/path.
-f — Force installation even if prefix -p already exists.
ref: https://docs.anaconda.com/anaconda/install/silent-mode/#linux-macos
Try the yes command.
yes | ./Anaconda3-5.1.0-Linux-x86_64.sh
As for your question
What if the last option is asking if I want to install Visual Studio
Code, which I'd like to answer no to?
Try this
yes no | ./Anaconda3-5.1.0-Linux-x86_64.sh
Or replace "no" with whatever you feel is the appropriate response.
It seems you've already found the -b flag,
but for reference,
here is small, complete scrip
that installs anaconda in $HOME/anaconda3.
#!/usr/bin/env bash
_anaconda_version=2020.02
_anaconda_file="Anaconda3-${_anaconda_version}-Linux-x86_64.sh"
cd
rm -f ${_anaconda_file}*
rm -rf anaconda3/
wget https://repo.anaconda.com/archive/${_anaconda_file}
bash ${_anaconda_file} -b
echo "y" | conda update --all
rm ${_anaconda_file}
unset _anaconda_version _anaconda_file
I am getting this error while cloning the site on aegir
Unknown option: --profile. See drush help provision-backup for available >options. To suppress this error, add the option --strict=0. [2.39 sec, 21.19 MB]
I am using aegir3 on ubuntu 14.04.4. Can anyone please help me solve this. I have searched on web but there is no solution regarding this issue. This issue also occurs while migrating.
you might find more Aegir users at the new community support forum
http://ask.aegir.support/
I had a similar issue and found a solution there
I found that debugging Aegir issues was a lot easier if you executed the Drush commands directly.
You can find the command by looking through the Log Messages keeping an eye out for entries like
Backend invoke: /usr/bin/php -d magic_quotes_gpc=Off -d magic_quotes_runti... (Expand)
Below entries like the above you will find the command that was executed, expand that by clicking the (Expand) and copy the command (I found sometimes the expand did not work, in cases like this I just use chrome tools to look at the source and copy it)
/usr/bin/php -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d magic_quotes_sybase=Off /var/aegir/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php --php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d magic_quotes_sybase=Off' --backend=2 --yes #centosintranet provision-install-backend --client_email='this.email#is.invalid' 2>&1
All you need to do now is run this as the Aegir user via bash. If you use the apt-get package to install Aegir you should be able to open a terminal and enter
sudo su - aegir -s /bin/bash
You will be prompted for your password, after entering it you will have a bash shell as the Aegir user. Paste in the above drush command and press enter.
Watch it execute, I found it easier to work out what was going on by removing the --backend=2 option. If you still can't see what the issue is try adding -vvv or --debug to the drush command.
Using this method I have solves all issues I have run into thus far when Aegir falls over.
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.
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 3 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I'm trying to update httpd.conf in my Cedar-based Heroku app. I got to my Heroku bash with
heroku run bash
and found the conf dir under apache. But when I try to open any editor vi, vim, or emacs, I can't find any of these programs. How do you edit conf files on Heroku?
I recently turned the original gist into a heroku cli plugin.
Just install:
heroku plugins:install https://github.com/naaman/heroku-vim
And use:
heroku vim
The heroku vim command will drop you into a bash shell with vim installed on your $PATH. All you have to do is retrain your fingers to type heroku vim instead of heroku run bash.
If you don't want to mess around with plugins and just want a copy of nano in your one-off dyno, just run
mkdir /app/nano
curl https://github.com/Ehryk/heroku-nano/raw/master/heroku-nano-2.5.1/nano.tar.gz --location --silent | tar xz -C /app/nano
export PATH=$PATH:/app/nano
This will download a copy of nano from this plugin and put it in your PATH.
there's ed if you're a masochist.
It looks like you can download and install vim for one session:
#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
This idea was found here.
Even if you could edit the files with vi it probably wouldn't solve your problem because the file system is ephemeral. Meaning... If you edit a file via heroku run bash you aren't actually changing the file for other dynos. To change a file for all dynos you need to either change what you push in a Git repo or change the buildpack. More details:
https://devcenter.heroku.com/articles/oneoff-admin-ps#formation-dynos-vs-oneoff-dynos
The plugin provided by Naaman Newbold is no longer working with heroku-16 stack, so I made a new plugin out of this updated gist.
Install:
heroku plugins:install #jasonheecs/heroku-vim
And use:
heroku vim
In the comments on the Brian Takita's answer link, there is the more recent solution to get Vim working on the Heroku console:
https://gist.github.com/dvdbng/7375821b20f189c189ab1bd29392c98e
Just saved me a lot of time! :)
Debugging on Heroku
Prepare the dyno
After installing naaman/heroku-vim you can create a new ephemeral dyno via heroku vim. As pointed out correctly by other posts you won't be able to see your changes when viewing through the browser because changes won't be propagated, but... you can actually view the changes from inside the dyno itself.
I've only experimented with "browsing" via curl, but if you could get lynx on there, or better yet get an ssh tunnel -- could be really great.
Start the server
The web server won't be running when you instantiate heroku-vim so you'll need to do it yourself. In my example I'm running php:
~ $ cat Procfile
web: vendor/bin/heroku-php-apache2
You can start this command yourself!
~ $ vendor/bin/heroku-php-apache2 2>/dev/null &
[2] 845
It's now running in the background!
curl your website
Dynos start up on random ports. Luckily you know which one because it's the $PORT variable!
~ $ curl localhost:$PORT
Hello World!
Editing
Do your vim thing now, but when you save the file and curl again - you won't see the changes. I don't understand where it's cached, but it's cached. You have to kill the server and restart it.
Restarting the server
Find the process id
~ $ ps -f
UID PID PPID C STIME TTY TIME CMD
u6897 3 1 0 05:34 ? 00:00:00 bash
u6897 582 3 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
u6897 652 582 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
u6897 653 582 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
Here 582 is the parent id -- use that.
kill 582
Wait just 1 second, and then start the server again (you'll get a new process id!). Curling via the same command will now give you the updated page.
An urgent alternative to edit a file in Heroku:
place a copy of it on some remote host. I like to use Gist
edit the file on Gist and when finished get the raw URL to it
wget the raw URL on your Heroku bash
copy the fetched file to the path of original file
I wrote a complete article on How to Edit a File on Heroku Dynos using Nano or Vim, but basically:
You can use command line:
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
You can use Heroku Plugins: heroku-vim
You can use Heroku Buildpacks: heroku-buildpack-vip
Hope it helps!
If you would like to just view the contents of the file then:
cd to the folder where the file is located e.g. $ cd folder
run cat command + the filename e.g. $ cat filename.csv
There are now a number of buildpacks that include vim: https://elements.heroku.com/search/buildpacks?q=vim
You could add one of these to the Heroku app in question, using support buildpack support.
the alternative way if your server run php is to upload PHP File Manager, it single file and you can download it from
http://phpfm.sourceforge.net/
One can change files in a dyno and see the result without pushing to Heroku:
Install heroku-buildpack-vim buildpack:
$ heroku buildpacks:add \
https://github.com/carloluis/heroku-buildpack-vim
Ssh into a dyno:
$ heroku ps:exec
Create and run start.sh:
#!/usr/bin/env bash
set -eu
export DATABASE_URL=...
bin/rails s -p 4000
Forward port 4000 (second console):
$ heroku ps:forward
Open localhost:4000 in your browser.
Stop start.sh, change a file, start again, refresh the browser page.
I prefer Nano editor, you can use following buildpack...
https://github.com/velizarn/heroku-buildpack-nano