Hot answers tagged

13

For Ubuntu 16.04+ using systemd (the default). systemd-inhibit --why="Wait for this script to finish" bash script.sh === Test: $ systemctl poweroff Operation inhibited by "bash script.sh" (PID 23912 "systemd-inhibit", user rinzwind), reason is "Wait for this script to finish". Please retry operation after closing inhibitors and logging out other users. ...


7

Using grep ifconfig | grep -oP '(?<=inet addr:)[\d.]+' This uses grep's Perl-style regular expressions to select the IP address that follows the string inet. So, to save that in a variable, just put both commands inside the $(): output=$(ifconfig | grep -oP '(?<=inet addr:)[\d.]+') The above will save the IP addresses for all active interfaces ...


4

By default subprocess.call doesn't use a shell to run our commands you so can't shell commands like cd. To use a shell to run your commands use shell=True as parameter. In that case it is recommended to pass your commands as a single string rather than as a list. And as it's run by a shell you can use ~/ in your path, too: subprocess.call("(cd ~/catkin_ws/...


4

subprocess.call() expects a list, with first item obviously being a legitimate shell command. Compare this for instance: >>> subprocess.call(['echo hello']) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/subprocess.py", line 523, in call return Popen(*popenargs, **kwargs).wait() ...


3

ifconfig might disappear in the future, it is deprecated in some linux (maybe some ubuntu versions, but read on). ip from the iproute2 package (should be installed by default) gives ip addr list and can be abbreviated to ip a and combined with ip a | grep -o -P '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(?=/)' to filter on all IPv4 look alike ...


3

~/.profile, /.bash_profile, and /.bash_login are better for defining the environment variables and setting up the environment, than for running scripts. I would not recommend these. /etc/rc.local can be used for that, but remember that it will start before GUI starts . Unless it is for a script that only sends notification to GUI. Note that you will need ...


3

Basically, you want this structure if grep -q "un-clean" /path/to/log_file.log ; then # put some command in case we find result is unclean else # if the output is ok, do something else fi All it does is to silently (without printing to screen) check if there is a match of string "unclean" in the file . If there is we do the if part, otherwise - ...


3

Check out the suggested answers before posting. The first suggested answer is this one: Split a large file into smaller files and then integrate them to get the original file And here the commands split -b 20M -d bigfile bigfile-part cat bigfile-part* > bigfile Edit: ... and for the hashsum part, you can generate a SHA512 checksum file from the ...


2

I've coded two small scripts that can be used for that. First, put the script (name it 'splitter' or anything you like) in a separate folder with the file to be splitted then in the bash run: ./splitter FILE SIZE Being FILE the file to be split and SIZE the size in MB. After that, you will see all the splitted blocks (SPLITTED_FILE.aa, SPLITTED_FILE.ab, ...


2

Suppose we run some kind of python script via python stuff.py. We can easily find it's PID via pgrep $ pgrep -f stuff.py 7573 And kill with pkill in a similar fashion. $ pkill -f stuff.py If you want to kill only the child process, and not script itself, then we ...


2

There is timeout command . Just place it before the command you want to run and add time limit. For example: timeout 3 find / From info timeout documentation: ‘timeout’ runs the given COMMAND and kills it if it is still running after the specified time interval. Synopsis: timeout [OPTION] DURATION COMMAND [ARG]... COMMAND must not be a ...


2

Use os.chdir() instead. Apart from the issues, mentioned in the existing answers, I wouldn't prefer using shell=True, nor subprocess.call() here to change directory. Python has its own way of changing directory in os.chdir() (don't forget to import os). ~ ("home") can be defined in several ways, a.o. os.environ["HOME"]. Reasons to prefer that over shell=...


2

The rhash manual states (emphasis mine): -u, --update Update hash files specified by command line. The program calculates and appends hashes to the updated hash file in the format specified by formating options. Hashes are calculated for those files from the same directory as the hash file, which ...


1

The portion of the error message you want to look at is: /etc/pm/power.d/99macbookair6: Permission denied which says you do not have sufficient permission to execute /etc/pm/power.d/99macbookair6. Even if you have some command here executable by you, you would still get permission denied error for: echo 0 > /sys/module/hid_apple/parameters/iso_layout ...


1

Simple way to print only the IP address regardless of interface using Grep; since that was the question ifconfig |grep -o -P '(?<=addr:).*(?= Bcast:)' addr: is the start string Bcast is the end string Anything in between those two strings gets printed using .*


1

In order to make a desktop notification appear put this code into a file whose extension you should put as .html, then run it using Firefox. Double-clicking it should do the trick in most cases. <!DOCTYPE html><html><head><script type='text/javascript'> var RunOnDomReady = function() { function authorizeNotification(){Notification....



Only top voted, non community-wiki answers of a minimum length are eligible