I'm trying to install VirtualBox on a Linux system. When running the installer, I run into an error due to not having bzip2 on this system:
# bash -i VirtualBox-5.2.16-123759-Linux_x86.run
Verifying archive integrity... All good.
Uncompressing VirtualBox for Linux installation.............
VirtualBox Version 5.2.16 r123759 (2018-07-16T15:17:42Z) installer
Removing previous installation of VirtualBox 5.2.16 r123759 from
/opt/VirtualBox
Installing VirtualBox to /opt/VirtualBox
./install.sh: line 252: bzip2: command not found
Unfortunately for me, I cannot get bzip2 installed on this system. However, I do have tar with the bzip2 support (the "j" flag). I cannot modify the .run file to use tar instead of bzip2, however.
So, my new idea is to use a function in bash, something along these lines:
function bzip2() { ... use tar to extract the bz2 file in a way that's compliant with the use case in the .run file ... }
A simple test, however, shows I cannot get the bzip2 function to be used in the .run file:
# bzip2() { echo $1; }
# bzip2 test
test
# bash -i VirtualBox-5.2.16-123759-Linux_x86.run
Verifying archive integrity... All good.
Uncompressing VirtualBox for Linux installation.............
VirtualBox Version 5.2.16 r123759 (2018-07-16T15:17:42Z) installer
Removing previous installation of VirtualBox 5.2.16 r123759 from /opt/VirtualBox
Installing VirtualBox to /opt/VirtualBox
./install.sh: line 252: bzip2: command not found
Functions are not exported into child processes by default. From Bash Reference Manual:
Functions may be exported so that subshells automatically have them
defined with the -f option to the export builtin.
$ cat script
#!/usr/bin/env bash
greet
$ greet() { echo hello; }
$ ./script
./script: line 2: greet: command not found
$ export -f greet
$ ./script
hello
Related
Currently I'm stuck at figuring out why a .sh script isn't running:
export DOWNLOAD_LOCATION=~/Downloads/
export VAGRANT_URL=https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.dmg
export VIRTUALBOX_URL=https://download.virtualbox.org/virtualbox/6.1.2/VirtualBox-6.1.2-135662-OSX.dmg
echo "===== Install Vagrant ====="
wget $VAGRANT_URL -P $DOWNLOAD_LOCATION
hdiutil attach $DOWNLOAD_LOCATION"vagrant_2.2.6_x86_64.dmg"
sudo installer -pkg /Volumes/Vagrant/vagrant.pkg -target /
echo "===== Install VirtualBox ====="
wget $VIRTUALBOX_URL -P $DOWNLOAD_LOCATION
hdiutil attach $DOWNLOAD_LOCATION"VirtualBox-6.1.2-135662-OSX.dmg"
sudo installer -pkg /Volumes/VirtualBox/virtualbox.pkg -target /
echo "===== Install MiniKF ====="
vagrant init arrikto/minikf
vagrant up
Windows is telling that:
./install.sh: line 9: wget: command not found
./install.sh: line 10: hdiutil: command not found
./install.sh: line 11: sudo: command not found
I have wget installed in Visual studio, do I need to install it for windows?
why a .sh script isn't running
It is calling commands, which are not available, namely wget, hdiutil, sudo.
There exist GNU Wget for Windows, which is wget.exe file and after placing in current working directory calls for wget and wget.exe should work, however hdiutil is more important here. My cursory search did not unveil hdiutil for Windows, so even if you make wget working you still need find some way to use .dmg file in your Windows system.
I am labouring since a while, to get rid of a conflict between the system Perl (MacOS, Catalina: v5.18.4) and the Homebrew Perl (v5.30.1). The modules are installed in ~/perl5
But I am realising, that also the system Perl uses for the modules ~/perl5
Here are some infos from my Shell (zsh):
which perl
/usr/local/bin/perl
ls -l /usr/local/bin/perl
lrwxr-xr-x 1 mstep admin 30 11 Jan 19:17 /usr/local/bin/perl -> ../Cellar/perl/5.30.1/bin/perl
Thats the Perl from Homebrew (v5.30.1). Some other infos from the System-Perl and
env | grep PERL
PERL5LIB=/Users/mstep/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=/Users/mstep/perl5
PERL_MB_OPT=--install_base "/Users/mstep/perl5"
PERL_MM_OPT=INSTALL_BASE=/Users/mstep/perl5
/usr/bin/perl -V
...
%ENV:
PERL5LIB="/Users/mstep/perl5/lib/perl5"
PERL_LOCAL_LIB_ROOT="/Users/mstep/perl5"
PERL_MB_OPT="--install_base "/Users/mstep/perl5""
PERL_MM_OPT="INSTALL_BASE=/Users/mstep/perl5"
#INC:
/Users/mstep/perl5/lib/perl5/5.18.4/darwin-thread-multi-2level
/Users/mstep/perl5/lib/perl5/5.18.4
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level
/Users/mstep/perl5/lib/perl5
/Library/Perl/5.18/darwin-thread-multi-2level
/Library/Perl/5.18
...
perl -e 'print join("\n",#INC)'
/Users/mstep/perl5/lib/perl5/5.30.1/darwin-thread-multi-2level
/Users/mstep/perl5/lib/perl5/5.30.1
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level
/Users/mstep/perl5/lib/perl5
/usr/local/Cellar/perl/5.30.1/lib/perl5/site_perl/5.30.1/darwin-thread-multi-2level
/usr/local/Cellar/perl/5.30.1/lib/perl5/site_perl/5.30.1
/usr/local/Cellar/perl/5.30.1/lib/perl5/5.30.1/darwin-thread-multi-2level
/usr/local/Cellar/perl/5.30.1/lib/perl5/5.30.1
/usr/local/lib/perl5/site_perl/5.30.1
In my .zshrc file I tried everything to no avail; just for now, I commented everything out:
# PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
# eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
# eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
# PATH="/Users/mstep/perl5/bin${PATH:+:${PATH}}"; export PATH;
# PERL5LIB="/Users/mstep/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
# PERL_LOCAL_LIB_ROOT="/Users/mstep/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
# PERL_MB_OPT="--install_base \"/Users/mstep/perl5\""; export PERL_MB_OPT;
# PERL_MM_OPT="INSTALL_BASE=/Users/mstep/perl5"; export PERL_MM_OPT;
# PERL_MM_OPT="INSTALL_BASE=/Users/mstep/perl5"; export PERL_MM_OPT;
# PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
Every time I am starting my ZSH it starts with installing Running install for module 'local::lib' and ZSH is complaining, that YAML is not installed, finishing with the following error; if I leave some lines of perl5-definition in my .zshrc it is even issuing this error twice:
Dumper.c: loadable library and perl binaries are mismatched (got handshake key 0xc500080, needed 0xc400080)
How to educate the system perl, to use the right module folder? I would be very grateful for any help!
marek
ps: Thx for your answers:
find /Users/mstep/perl5/lib/perl5 -name '*Dumper*' /Users/mstep/perl5/lib/perl5/PPIx/Regexp/Dumper.pm
/Users/mstep/perl5/lib/perl5/PPIx/QuoteLike/Dumper.pm
/Users/mstep/perl5/lib/perl5/Module/Build/Dumper.pm
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/.meta/Data-Dumper-2.173
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/auto/Data/Dumper
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/auto/Data/Dumper/Dumper.bundle
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/DBI/ProfileDumper.pm
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/DBI/Gofer/Serializer/DataDumper.pm
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/DBI/ProfileDumper
/Users/mstep/perl5/lib/perl5/darwin-thread-multi-2level/Data/Dumper.pm
/Users/mstep/perl5/lib/perl5/YAML/Dumper.pm
/Users/mstep/perl5/lib/perl5/YAML/Dumper.pod
/Users/mstep/perl5/lib/perl5/YAML/Dumper
/Users/mstep/perl5/lib/perl5/PPI/Dumper.pm
I recently had this issue, so thought I'd post the solution here as I couldn't find it anywhere.
The issue was a broken cpanm install (recipe?) from brew - the first line of which (the shebang of /usr/local/bin/cpanm) was using the system perl.
I had to run
brew reinstall cpanm
because the problem is now fixed in that recipe, though the version was not bumped.
I could then reinstall my perl modules (e.g. cpanm --reinstall JSON::XS) to get things working.
I tried to execute a shell script on AIX and it failed because some declaration/instructions (like readarray, array declaration, date command with specific args etc) from shell is not recognized in ksh
I would like to execute this linux script on AIX without rewrite the entire script in ksh.
I tried to run the script using different shebang like #!/usr/bin/env bash or #!/bin/sh but AIX seems still running it through ksh.
Would someone have a solution to run linux shell on AIX ?
« AIX Toolbox for Linux Applications » seems provide to execute linux shell on AIX.
Could someone confirm me this information ?
How can I check if AIX Toolbox is already install on the AIX server ? (i don’t have the administration right on this server)
How to execute AIX Toolbox to run shell script ?
Thanks in advance for your help
As you can see from the link you can install AIX Toolbox for Linux Applications and you will have bash. Also you can download only this package and install it.
After install you can exec bash as any other program in your OS.
But in generally you can reach a lot of challenges when try to run linux script on AIX or HP-UX.
You can use bash! Need to install yum from here. Once yum is installed it will auto-install bash package.
Put in a temporary empty folder, untar it and install all RPMs: rpm -Uvh *.rpm.
Edit /etc/security/login.cfg anb and "/usr/bin/bash" in the end:
shells = /bin/sh,/bin/bsh,/bin/csh,/bin/ksh,/bin/tsh,/bin/ksh93,/usr/bin
/sh,/usr/bin/bsh,/usr/bin/csh,/usr/bin/ksh,/usr/bin/tsh,/usr/bin/ksh93,/usr/bin/
rksh,/usr/bin/rksh93,/usr/sbin/uucp/uucico,/usr/sbin/sliplogin,/usr/sbin/snappd,
/usr/bin/bash
Add path /usr/bin/bash to /etc/shells:
# echo “/usr/bin/bash” >> /etc/shells
Change shell to se bash:
# chuser shell=/usr/bin/bash root
Create a new .bash_profile inside root's home with:
# .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PS1="[\u#\h \w]\$ "
export PS1
Login with root and you see something like this:
[root#aixserver ~]#
I am running a non-standard version of Ubuntu and I tried to patch the shell shock bug by downloading and recompiling from the source, following the instructions from https://news.ycombinator.com/item?id=8364385 . After make install, running bash --version shows 4.3.24(2). But when running the bug test:
env var='() { :;}; echo vulnerable' bash -c /bin/true
is still printing vulnerable . Am I doing something wrong?
4.3.24 is from August 2014; you need 4.3.25.
It's most likely that you didn't install the new bash in the right place. Or that you didn't manage to install it at all.
make install will only work if you're running as root. Normally, you would need to do
sudo make install
If you don't, you'll see an error message:
$ make install
***********************************************************
* *
* GNU bash, version 4.3.25(1)-release (x86_64-unknown-linux-gnu)
* *
***********************************************************
mkdir -p -- /usr/local/share/doc/bash
mkdir: cannot create directory ‘/usr/local/share/doc/bash’: Permission denied
make: *** [installdirs] Error 1
which means that the software wasn't installed. (You only need to redo the install step.)
Also, by default, the bash build files will install your new bash as /usr/local/bin/bash, while your old bash will continue to exist in /usr/bin/bash. Check which bash is being run by typing:
which bash
I've hit a snag with a shell script intended to run every 30 minutes in cron on a Redhat 6 server. The shell script is basically just a command to run a python script.
The native version python on the server is 2.6.6 but the python version required by this particular script is python 2.7+. I am able to easily run this on the command line by using the "scl" command (this example includes the python -V command to show the version change):
$ python -V
Python 2.6.6
$ scl enable python27 bash
$ python -V
Python 2.7.3
At this point I can run the python 2.7.3 scripts on the command line no problem.
Here's the snag.
When you issue the scl enable python27 bash command it starts a new bash shell session which (again) is fine for interactive commandline work. But when doing this inside a shell script, as soon as it runs the bash command, the script exits because of the new session.
Here's the shell script that is failing:
#!/bin/bash
cd /var/www/python/scripts/
scl enable python27 bash
python runAllUpserts.py >/dev/null 2>&1
It simply stops as soon as it hits line 4 because "bash" pops it out of the script and into a fresh bash shell. So it never sees the actual python command I need it to run.
Plus, if run every 30 minutes, this would add a new bash each time which is yet another problem.
I am reluctant to update the native python version on the server to 2.7.3 right now due to several reasons. The Redhat yum repos don't yet have python 2.7.3 and a manual install would be outside of the yum update system. From what I understand, yum itself runs on python 2.6.x.
Here's where I found the method for using scl
http://developerblog.redhat.com/2013/02/14/setting-up-django-and-python-2-7-on-red-hat-enterprise-6-the-easy-way/
Doing everything in one heredoc in the SCL environment is the best option, IMO:
scl enable python27 - << \EOF
cd /var/www/python/scripts/
python runAllUpserts.py >/dev/null 2>&1
EOF
Another way is to run just the second command (which is the only one that uses Python) in scl environment directly:
cd /var/www/python/scripts/
scl enable python27 "python runAllUpserts.py >/dev/null 2>&1"
scl enable python27 bash activates a python virtual environment.
You can do this from within a bash script by simply sourcing the enable script of the virtual environment, of the SCL package, which is located at /opt/rh/python27/enable
Example:
#!/bin/bash
cd /var/www/python/scripts/
source /opt/rh/python27/enable
python runAllUpserts.py >/dev/null 2>&1
Isn't the easiest to just your python script directly? test_python.py:
#!/usr/bin/env python
import sys
f = open('/tmp/pytest.log','w+')
f.write(sys.version)
f.write('\n')
f.close()
then in your crontab:
2 * * * * scl python27 enable $HOME/test_python.py
Make sure you make test_python.py executable.
Another alternative is to call a shell script that calls the python. test_python.sh:
#/bin/bash
python test_python.py
in your crontab:
2 * * * * scl python27 enable $HOME/test_python.sh
One liner
scl enable python27 'python runAllUpserts.py >/dev/null 2>&1'
I use it also with the devtoolsets on the CentOS 6.x
me#my_host:~/tmp# scl enable devtoolset-1.1 'gcc --version'
gcc (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
scl is the dumbest "let us try and lock you in` nonsense I've seen in a while.
Here's how I made it so I could pass arguments to a series of scripts that all linked to a single skeleton file:
$ cat /usr/bin/skeleton
#!/bin/sh
tmp="$( mktemp )"
me="$( basename $0 )"
echo 'scl enable python27 - << \EOF' >> "${tmp}"
echo "python '/opt/rh/python27/root/usr/bin/${me}' $#" >> "${tmp}"
echo "EOF" >> "${tmp}"
sh "${tmp}"
rm "${tmp}"
So if there's a script you want to run that lives in, say, /opt/rh/python27/root/usr/bin/pepper you can do this:
# cd /usr/bin
# ln -s skeleton pepper
# pepper foo bar
and it should work as expected.
I've only seen this scl stuff once before and don't have ready access to a system with it installed. But I think it's just setting up PATH and some other environment variables in some way that vaguely similar to how they're done under virtualenv.
Perhaps changing the script to have the bash subprocess call python would work:
#!/bin/bash
cd /var/www/python/scripts/
(scl enable python27 bash -c "python runAllUpserts.py") >/dev/null 2>&1
The instance of python found on the subprocess bash's shell should be your 2.7.x copy ... and all the other environmental settings done by scl should be inherited thereby.