append text string from file to a command - linux

How to put a text string from file to the end of a command?
What I want to is to use sudo dpkg -i with | or < or > (or whatever else) to input the strin from file in which would be the package names. To demonstrate it:
$ ls
file pkg1.deb pkg2.deb pkg3.deb pkg4.deb
$ more file
pkg1.deb pkg3.deb
$ sudo dpkg -i < file
and the installation of the selected packages should run.
Info: I am using Ubuntu 13.10 i386

$ sudo dpkg -i $(<file)
ought to work, assuming that dpkg -i can take multiple package names (don't have a debian box around to check). If not:
for X in $(<file) ; do sudo dpkg -i "$X" ; done

Related

Trying to use dpkg within a folder only on files with the keyword 'mono' in the title

I'm currently trying to install mono using dpkg, and all the other files within the same folder using apt-get, I know I need to use some form of this:
sudo grep 'mono' | dpkg -R --install >/dev/null
however there are too many unknowns for me to complete it and fill in whatever blanks there may be, any help would be greatly appreciated!
Try this:
ls | grep "mono" | sudo xargs dpkg -R --install >/dev/null
The ls will only give files from the current directory. You could also use ls -d *mono* instead of the ls and grep, but I think the ls and grep is easier to understand
The grep is as you had, but now has input from the ls to grep on. You can try ls | grep "mono" to see what files it selects.
Then the sudo is moved to the dpkg part of the script to make dpkg run as root. The way you had it grep runs as root and dpkg as your user
The xargs will take whatever input you had, and put it after the next command. It will take command line length limits in account and execute multiple dpkg commands if the command line gets too big. Note that if your files have spaces in their names, xargs will see the space as start of a new file and you will have problems. There are solutions to that, but really, the easiest solution is to have no files with spaces.
In this example, lets say there are 2 files from the grep "mono1.deb and "mono2.deb" the command executed will be dpkg -R --install mono1.deb mono2.deb. If for some reason you want only one deb per dpkg execution you can change it to ...xargs -n1 dpkg... and it will run dpkg -R --install mono1.deb and also dpkg -R --install mono2.deb
The >/dev/null make sure you won't get any output. Note that you will still get the errors though!

Linux ssh output of two commands in an input

I am looking for a command that will let me look for an rpm installed in my machine and remove it, the only information about the rpm to delete that I have is a suffix of its name, that's what I want to do in one command:
rpm -qa | grep -i $rpmnameSuffix >> output
rpm -e output
Use command substitution to substitute the output of a command into another command line.
rpm -e "$(rpm -qa | grep -i $rpmnameSuffix)"

List of valid suid/sgid executables on Linux?

Can anyone tell me where to find a list of valid suid/guid programs on Linux, ideally Ubuntu?
Note I can use find to get a list of suid/sgid programs on my machine, but I want to know if they are real valid programs; is there a list I can compare them against?
One answer (from Rmano on askubuntu, ) is copied below:
One idea - but will need a bit of work in scripting --- be my guest ;-)
Find a suid/sgid file; let's call it scommand
Check from which package has been installed:
dpkg -S /full/path/to/scommand
Compare its permission with the original deb package, by firstly downloading the package:
apt-get download package
Check if the command should have the suid set in the package with
dpkg -c package*deb | grep /full/path/to/scommand
cleanup, rinse, repeat.
Example:
[romano:~/tmp] % ls -l /bin/passwd
ls: cannot access /bin/passwd: No such file or directory
[romano:~/tmp] 2 % ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 47032 Feb 17 2014 /usr/bin/passwd
[romano:~/tmp] % dpkg -S /usr/bin/passwd
passwd: /usr/bin/passwd
[romano:~/tmp] % apt-get download passwd
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main passwd amd64 1:4.1.5.1-1ubuntu9 [755 kB]
Fetched 755 kB in 1s (487 kB/s)
[romano:~/tmp] % dpkg -c passwd*.deb| grep /usr/bin/passwd
-rwsr-xr-x root/root 47032 2014-02-17 03:42 ./usr/bin/passwd
Try this little script I wrote that searches the entire online archive of Ubuntu (or Debian or anything else that uses apt and dpkg, really):
PKG=$(apt-cache search . | cut -f 1 -d ' ');
echo $PKG | xargs apt-get download;
F=(`find *.deb`); for i in ${F[#]};
do dpkg -c $i | cut -c 4- | grep ^s | cut -c 4- | cut -f 2 -d '.';
done | tee suid_root;
Note that this takes a lot of disk space and bandwidth and isn't very optimized.

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.

Tool / command to query debian repository (like repoquery for rpm repository)

Im basically trying to query the latest version of a package given a repository url & package name.
So if http://in.archive.ubuntu.com/ubuntu/ is repository & gcc is package name then is there a command / tool which will help me find the latest version of it available?
i tried using apt-get & apt-cache
the problem is i do not want to add the repository url into /etc/apt/sources.list of the box since i dont have root access.
i tried running
apt-get update -o RootDir=<local-dir>
thinking i could then add the repository url into < local-dir >/etc/apt/sources.list & run
apt-cache show <pkg-name> -o RootDir=<local-dir>
but the apt-get update with a switched root-dir fails saying
chrooting into <local-dir>/
E: Sub-process returned an error code
Is this possible? or is there an alternative?
I don't know if there is an "official" way, but it's easy to write your own script that parses the package list:
#!/bin/bash
if [ -n "$1" ]
then
package="$1"
else
package="gcc"
fi
release=$(lsb_release -c|awk '{ print $2 }')
file=$(tempfile)
wget -o /dev/null -O $file http://in.archive.ubuntu.com/ubuntu/dists/$release/main/binary-amd64/Packages.gz
gunzip -qc $file | grep -A 10 "^Package: $package$" | awk '/Version/ { print $2 }'
rm $file
This works if you are running on Ubuntu and are looking for the packages matching your current version. If you're running on another distro, set
release="saucy"
for example.
Have fun!

Resources