Why this command destroyed my ubuntu 14:04 installation? - linux

I successfully used this command to remove all the old kernels from my system:
dpkg --list |
grep linux-image |
awk '{ print $2 }' |
sort -V |
sed -n '/'"linux-image-3.13.0-100-generic"'/q;p' |
xargs sudo apt-get -y purge
But when I used this modified version to un-install cups, dpkg started to remove packages unrelated to cups:
dpkg --list |
grep cups |
awk '{ print $2 }' |
sort -V |
xargs sudo apt-get -y purge
By the time I realized what was happening, my system had became already unbootable. I don't know if it's supposed to happen with xargs, but I could not stop the execution with a Ctrl+C sequence.

Related

Linux curl : no url found (or) curl: malformed url

So I am downloading docker setup on my linux vm, and have to run this command as part of the steps, but even though it mentions url, and I changed once -o to -O but still getting those errors, what to do for this?
this is the command im running
sudo curl -L $(curl -L https://api.github.com/repos/docker/compose/releases/latest | grep "browser_download_url" | grep "$(uname -s)-$(uname -m)\"" | sed -nr 's/\s+"browser_download_url":\s+"(https.*)"/\1/p') -o /usr/local/bin/docker-compose
The grep that is filtering what system you are running is outputting an upper case L in Linux, this may be the cause of your errors. Try this:
sudo curl -L $(curl -L https://api.github.com/repos/docker/compose/releases/latest | grep "browser_download_url" | grep -i "$(uname -s)-$(uname -m)\"" | sed -nr 's/\s+"browser_download_url":\s+"(https.*)"/\1/p') -o /usr/local/bin/docker-compose
Hope this helps!

Most efficient way to get the latest version of an rpm via web

This is my attempt using wget to pull down the web page, dig for latest tar file and rerun a wget to take it down. In the example, i'm taking down pip.
wget https://pypi.org/project/pip/#files
wget $(grep tar.gz index.html | head -1 | awk -F= '{print $2}' | sed 's/>//' | sed 's/\"//g')
gunzip -c $(ls | grep tar |tail -1) | tar xvf -
yum install -y python-setuptools
cd $(ls -d */ | grep pip)
python setup.py install
cd ..
I'm sure that there is a better way, perhaps only using one wget or similar
Do you mean like that?
wget $(curl -s "https://pypi.org/project/pip/#files"|grep -o 'https://[^"]*tar\.gz')

the command apt-get upgrade fails in puppet

I'm running a puppet master and I need to execute these commands on my puppet agent.
Lock kernel from updating
for i in $(dpkg -l "*$(uname -r)*" | grep kernel | awk '{print $2}'); do echo $i hold | dpkg --set-selections; done
Update
apt-get update -y
Upgrade
apt-get upgrade -y
apt-get update -y runs smoothly, but the other two aren't.
Can you give the correct Puppet syntax for this?
exec {'lock kernel from updating':
command => "bash -c 'for i in $(dpkg -l "uname -r" | grep kernel | awk '{print \$2}'); do echo \$i hold | dpkg --set-selections; done'",
}
exec{'update':
command => 'apt-get update -y',
}
exec{'upgrade':
command => 'apt-get upgrade -y',
}

getting SW version by bash script for uninstall preinstalled software/notifying easily by assigning variable to it. Please share more ideas

Please share more ideas to get software version from bash command and use it as variable later.
su --version
su (GNU coreutils) 5.97
Copyright etc.
and create variable of the result of it.
Something like I tried below.
su --version >/tmp/temp.txt
if [ -f /tmp/temp.txt ]; then
elv=`cat /tmp/temp.txt | gawk 'BEGIN {FS="(GNU coreutils)"} {print $2}' | gawk 'BEGIN {FS="."} {print $1}'`
#Version String. Just a shortcut to be used later
els=el$elv
else
echo "Unable to determine version. I can't continue"
exit 1
fi
if [ `rpm -qa | egrep -c -i "^mysql-"` -gt 0 ]; then
cat << EOF
It appears that the distro-supplied version of MySQL is at least partially installed,
or a prior installation attempt failed.
Please remove these packages, as well as their dependencies (often postfix), and then
retry this script:
$(rpm -qa | egrep -i "^mysql-")
EOF
exit 1
fi

Pipes with Apt Package Manager

I have two files, the first one called packages.txt which is list of packages:
gcc
emacs
vim
python
...
Now, when I run the command
cat packages.txt | tr '\n' ' ' | apt-get install
This basically converts the file into one line of packages separated by space. It does not install all the packages in packages.txt. (I think it only installs the first one) Does anyone knows why?
Try using xargs:
xargs -d '\n' -- apt-get install < packages.txt
Or
xargs -d '\n' -n 1 -- apt-get install < packages.txt
Make sure packages.txt is not in DOS format:
sed -i 's|\r||' packages.txt
The pipe operator sends the stdout of one application into the next (as stdin. Unfortunately, apt-get does not read from stdin. Rather, apt-get takes a list of packages on the command line. I think what you are attempting to do is more along the lines of
apt-get install $(cat packages.txt | tr '\n' ' ')
or
apt-get install `cat packages.txt | tr '\n' ' '`
Which is to say evaluate the file list, and pass it in as an arguments to a single apt-get call.

Resources