I want to display a welcome message in the start of my script:
echo "Running $0 $@"
But $@
might be very long. How can I break this line into multiple up-to-80 character lines?
I want to display a welcome message in the start of my script:
echo "Running $0 $@"
But $@
might be very long. How can I break this line into multiple up-to-80 character lines?
Sorry about the non-informative heading...
What I'm looking for is something like that will allow me to shorten redirecting stdout. I know that executing a command with whitespaces before it does not write it into history, and there are a few "magic" operators, such as "!!", etc.
I'm basically looking for something like that, that would allow me to replace >/dev/null
, so, I'll be able to write, for example
git pull !!!
and that would be equivalent to git pull>/dev/null
Is there something like this? Am I able to override an existing operator / write a new one?
I have a number .deb packages I create and install:
I'm able to install them using sudo dpkg -i pkg1_1.0_all.deb
.
Now I want to create a meta package that will depend on all of them, allowing me to only install sudo dpkg -i meta_1.0_all.deb
.
I used equivs
to create a control file:
Section: misc
Priority: optional
Standards-Version: 3.6.2
Package: bla
Version: 1.0
Depends:
Description:
long description and info
.
second paragraph
and install it.
Then I modified the Depends:
to depend on a known package: Depends: tmux
and installed it.
Next, I tried to depend on my custom packages: Depends: pkg1
and now installation broke:
dpkg: dependency problems prevent configuration of bla:
bla depends on pkg1; however:
Package pkg1 is not installed.
which is understandable, as pkg1
is indeed not installed.
I have added my local directory as a debian source following this guide (changed one thing - added [trusted=yes]
to the sources list deb [trusted=yes] file:...
so it would work)
I hoped this would allow me to sudo apt install ./meta_1.0_all.deb
and it would find the dependent package in my current dir, but it failed again with the same error.
What can I do to allow user to install one .deb and to make it install several local .deb packages?
I want to run a service on a custom port (e.g. jenkins on 8080) and I prefer to access it via browser with a name I can remember, e.g. http://localhost:jenkins
which will be an alias for http://localhost:8080
Edit:
I have a pkg with some c++ code. Currently I'm compiling some of the c++ code as binary, some as library, and I can ship and deploy it on other platforms.
However, I also have a driver there, which I can't cross compile due to its dependency on the kernel, which makes it so that every kernel might need a different binary.
So, what I want to have is a .deb where I will store the binary under /usr/bin (done), the library under /usr/lib (also done) and the driver source code under /opt/driver (I guess... Is this a legit place for that?)
Packing this is the easy part, since all I need to do is put it in my workspace, and call dpkg-deb
. What I'm not sure about are two things
dpkg / apt
do that for me? Or do I need to run dpkg -i pkg
and then run make
? [looking at postinst but I'm not sure if this is the right way to go]I'm open to any kind of build system if it can solve this though I'm currently using cmake and would much prefer sticking to it
My POC:
tree bla_x86_64
bla_x86_64
├── DEBIAN
│ ├── control
│ └── postinst
├── opt
│ └── bla.cpp
└── usr
├── bin
│ └── bla.bin
└── lib
└── bla.lib
cat bla_x86_64/DEBIAN/postinst
#!/bin/sh
set -e
echo hello world!
echo compiling $(ls /opt/bla.cpp)
echo cleanup
rm -rvf /opt/bla.cpp
$ dpkg-deb --build --root-owner-group bla_x86_64/
dpkg-deb: building package 'bla' in 'bla_x86_64.deb'.
$ sudo dpkg -i bla_x86_64.deb
(Reading database ... 407519 files and directories currently installed.)
Preparing to unpack bla_x86_64.deb ...
Unpacking bla (4.0) over (3.0) ...
Setting up bla (4.0) ...
hello world!
compiling /opt/bla.cpp
cleanup
removed '/opt/bla.cpp'
I'm trying to have a shortcut for going back a few dirs. Something like "cd ...." == "cd <number of dots - 1> * '../'"
function bla { for i in $(seq $(($1 - 1))); do cd ../; done; }; bla 3
but that seems less elegant (and also I cd ../ one in a time which is bad (cd -
won't have the desired effect for example) but I can concat the strings and only cd at the end)My questions are: How to solve (1) & (2) and is there a neater way for this?
I'm trying to automate the pairing of my headset to my ubuntu16 machine.
I took this nice script and tried it, but it didn't work. I played around a bit, and found out that I can just work with this minimal script:
#!/usr/bin/expect -f
set prompt '#'
set address [lindex $argv 0]
spawn bluetoothctl &> /dev/null
expect -re $prompt
send "\nconnect <my_mac_addr>\r"
sleep 10
I save this as a ./bluetooth.sh and run it with ./bluetooth.sh & and it works like a charm. However, I get this annoying bluetoothctl
output:
[NEW] Controller *** ### [default]
[NEW] Device *** A
[NEW] Device *** B
[NEW] Device *** C
[bluetooth]#
I tried removing it with the redirection I added to the spawn command, but it didn't help as you can see...
Removing the expect
would work, but I'm not sure this is the way to go...
I have a script installing graphviz-dev on my machines. The relevant line is sudo apt install graphviz-dev
In Ubuntu 16.04 it installs a package called graphviz-dev, and dpkg -s graphviz-dev
will return a good response
However, on Ubuntu 18.04 it installs a different package - libgraphviz-dev, and now dpkg -s graphviz-dev
won't work, but dpkg -s libgraphviz-dev
would.
Is there a better way to check if the installation of said package (graphviz-dev
) was successful, even if APT decided to redirect and install a different package instead?
I have 2 repositories. In both I'm running a similar command (in Python's multiprocess
, with 2 seconds sleep between).
The command is a python script I have, and I'm running it via each repo's virtualenv (created with python3.5)
How is it one repo gives this error and the other does not? I tried reproducing without multiprocessing
and it does reproduce. One repo is flawed somehow in its libc6 search.
I pre-installed sudo apt install libc6-dev libc6-dbg libc6-amd64
Given a list of dev packages (e.g. pkgs="python3.5-dev python3-tk"), would there be a difference between running
sudo apt-get install $pkgs
vs.
for p in $pkgs; do sudo apt-get install $p; done
I'm asking mostly dependencies-topo-sort related, i.e. will there be different packages downloaded and installed in either way
I somehow got this file \.\pipe\FC_{6D57D5C3-9CEA-4497-BE57-9E544137A437}_1 on my home dir.
Tried deleting with rm and tab completion using the following prefixes:
but it seems to ignore this file entirely
The file is weird (ll-ing the dir):
srwxr-xr-x X Y 0 Aug 13 19:28 \\.\pipe\FC_{6D57D5C3-9CEA-4497-BE57-9E544137A437}_1=
and it can't be ls-d:
ls: cannot access '\.\pipe\FC_{6D57D5C3-9CEA-4497-BE57-9E544137A437}_1=': No such file or directory
I have a error handler script that shows my important environment variables when I fail (I added a few Enter in the echo string for easier reading, the full line is added at the end of the question):
echo -e "--- failed at line $1 in function $2\nvirtual env =
$(echo ${VIRTUAL_ENV})\ncurrent dir = ${PWD}\nbranch = $(git status | head
-1)\ngit commit = $(git log -1 | tr '\n''\t')\npip version = $(pip -
V)\nPy version = $(python --version)\nhostname = $(logname)@$(hostname)\n"
I get a good result, except for the python --version part:
Python 2.7.12 <--- why is this here?
--- failed at line 186 in function my_func
virtual env =
current dir = /home/bla/blabla/foo
branch = On branch goo
git commit = commit ### Author: ...
pip version = pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip-18.1-py2.7.egg/pip (python 2.7)
Py version = <----- instead of here
hostname = X@Y
The actual function of mine doesn't use echo right away. I also call tput setaf
&& tput sgr0
to modify the colors. The python line (the 1st) is not colored, while the others are...
"--- failed at line $1 in function $2\nvirtual env = $(echo ${VIRTUAL_ENV})\ncurrent dir = ${PWD}\nbranch = $(git status | head -1)\ngit commit = $(git log -1 | tr '\n''\t')\npip version = $(pip -V)\nPy version = $(python --version)\nhostname = $(logname)@$(hostname)\n"
I have a script that gets N params. It first parses them (extracts a specific value X
), then calls another program with said value:
function main() {
parse "$@"
run "$@"
}
main "$@"
I want to add an optional param at the start of the args list (param to set the python version I'm running). So I added this to the parse functoin:
if [ "$1" = '2' ] || [ "$1" = '3' ]; then version=$1 && shift; else version=2; fi
However, after the parse ends, I'm stuck because the shift
doesn't affect the run function. How can I do this without checking again the value of the first value (which would defeat the whole purpose of having a parse function)
I want to find some dirs and delete all but the 10 latest dirs.
I can find . -maxdepth 1 -type d -name "XXX*" | xargs rm -rf
but that would remove all of them.
I can't use head / tail
because I don't know the length of the list. I thought of piping the result to wc -l
and then doing subtracting 10 from it and then rm -rf
'ing it, but I don't know how...
What I came up till now is this:
find . -maxdepth 1 -type d -name "XXX*" | # get the dirs list
wc -l | # count number
xargs -I{} expr {} - $(find . -maxdepth 1 -type d -name "XXX*") # send number to xargs and try to use expr to subtract from it the tail of the find
I'm stuck in the expr
part and how to cut the list where I want
I have this small script for connecting to new machines I don't have ssh-key to:
function my_ssh () {
ip=$1
optional_cmd=$2
ssh -o "BatchMode yes" user_name@$ip exit > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "1st time connection - adding key to authorized keys list"
sshpass -p "secret_password" ssh-copy-id user_name@$ip
fi
echo $optional_cmd
ssh -X user_name@$ip $optional_cmd
}
This works weel for servers that either have my ssh-key, or only ask for a password in order to use ssh-copy-id. However, some servers require a "yes/no" after the following question:
The authenticity of host 'A.B.C.D ()' can't be established. ECDSA key fingerprint is SHA256:****. Are you sure you want to continue connecting (yes/no)?
How can I add a "yes" string echoed into the server question stdin and then use the sshpass?
ps, I went over the sshpass code from github but it doesn't seem sshpass
is designed for something like this. I think I can modify it to suite my needs, but I prefer using a normal Linux mechanism if possible
Given a line like this: "hello my (name) is (user)
, how can I remove all '()'
using sed?
What I'm currently doing is highlighting the line using visual block, and then :s/(//g
and again for )
. Is there a way to remove both (, )
in one sed command?
My end goal is "hello my name is user"
When I run grep "keyword" -n
and get the following list of results:
a/b/c:10: keyword
a/b/c:70: keyword
a/b/d:50: keyword
How can I open one of the files (say the 2nd in list) in the line it found?
I now just copy the the output using my mouse, and copy it after vim
and then add +
with the line number I copy. (meaning I write vim a/b/c +70
using the mouse copy to get the file name, and another mouse copy to get the line number [or I just copy it by hand, when its short enough])
Is there a way to do it with a keyboard shortcut?
I wanted to list all functions in 2 files I have, so I used:
cat <file_A> | grep -E "^function"
cat <file_B> | grep -E "^function"
How can I compare the outputs and highlight the similarities?
I have a directory that I is filled by another user, and I'm tasked with maintaining it. I want to delete all its content except a 2 files with a specific name. Is it possible with rm
or should I do this:
cp aaa/a ./a && cp aaa/b ./b && rm -rf aaa/* && mv ./a aaa/a && mv ./b aaa/b
where aaa
is the directory, a,b
are the files I want to keep, and there are (at least, there may be) other files/directories in there.
Is there a better (and shorter) way?
when I want to see the content of a dir I use ~/
+ Tab and it shows me
.bashrc.swp .gitconfig .local/ ...
Is there a way to make the results separated by newlines?
i.e.
.bashrc.swp
.gitconfig
.local/ ...