New answers tagged

0

You could use mutt to do this from cron with expect (or one of its many implementations in many other languages). #!/usr/bin/env expect spawn mutt -f alerts expect -ex "Mutt" # or something if you've customized the display send -- "D" send -- "syscheck@example.com" ... Another option would be to write code that does a similar thing via something like ...


0

Bringing back a file to its orginal location is not different from moving a file to that location. In Linux you do that with the mv command: mv /path/to/output/location/your_file.ext /path/to/original/location You can of course include this line (at the end of) any script that creates the file at the output location.


0

The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself. If you don't get a sudo prompt, then what happens is: The shell reads whole lines until it has a complete command. The first line starts ...


0

It's possible to do this in sh, but not very efficient for large strings. compare_characters () { tail1="$1" tail2="$2" if [ "${#tail1}" -ne "${#tail2}" ]; then echo >&2 "The strings have different length" return 1 fi while [ -n "$tail1" ]; do h1="${tail1%"${tail1#?}"}" h2="${tail2%"${tail2#?}"}" if [ "$h1" = "$h2" ]; then ...


3

For python at least I recomend "Learn Python The Hard way", by Zed Shaw. Freely available online. Good stuff. Not sure if posting a link here is technically advertising... Here goes. Free Book


2

There are many. I can suggest two for python: codecademy: to learn syntax and get a basic understanding of the langauge newcoder.io: some projects to go further


3

To avoid running one dig and read per line of the file, you could do: dig -f domains.txt mx +noall +answer Which would give an output like: stackexchange.com. 300 IN MX 5 alt1.aspmx.l.google.com. stackexchange.com. 300 IN MX 1 aspmx.l.google.com. stackexchange.com. 300 IN MX 10 ...


0

var1="string1" var2="string2" i=1 l=${#var1} while [ ${i} -le ${l} ] do c1=$(echo ${var1}|cut -c ${i}) c2=$(echo ${var2}|cut -c ${i}) if [ ${c1} == ${c2} ] then printf "True (${c1}) " else printf "False " fi (( i++ )) done If the string length of the two variables are not the same, the result is ambiguous. This script assumes both ...


1

In case both have same character length: string_1="hello" string_2="hilda" for (( i=0; i<${#string_1}; i++ )); do [ "${string_1:$i:1}" == "${string_2:$i:1}" ] && echo "true" || echo "false" done


1

The following is probably what you're looking for: l1=Hello l2=Hlleo count=`echo $l1|wc -m` for cursor in `seq 1 $count` do c1=`echo $l1|cut -c$cursor` c2=`echo $l2|cut -c$cursor` if test "$c1" = "$c2" then echo "true ($c1), " else echo "false ($c2 instead of $c1), " fi done


-1

Just egrep -o 'https?://[^ ")]+' which will include url() and "http"


0

Assuming you want the first 5 characters of a filename: As you say characters, cut will not work in general, as it cuts on bytes. But if it is exactly five characters, the POSIX portable ${var#?????} could be used, as this: filename='def12345' result=${filename%"${filename#?????}"} echo "$result"


0

Posix-compliant cut can also cut by character (or byte, which is not the same thing in UTF-8): cut -c-5 or cut -b-5 respectively


1

Using the shell's string manipulation functions You haven't specified in which script context you intend to use this, so I'll give you a generic example: Assuming shell variable $x holds the string abc12345, then ${x:0:5} will represent the first 5 characters of $x, i.e. abc12.


3

Not sure what you are doing wrong but the following works: for i in *; do cp "$i" $(date '+%Y%m%d')"$i"; done (you should only run this once in a directory)


4

What's probably happening is that the CPU goes into a more aggressive power-save mode. This causes the internal switch-mode voltage regulators to go into a pulse-skipping mode, moving the switching frequency down to the audible range. The noise comes from the inductors and capacitors, both being slightly microphonic (which also works in reverse; the emit ...


3

On Debian or Ubuntu install stress-ng with apt-get install stress-ng. Then run: stress-ng -c 1 -l 50 playing with -c (number of CPUs) and -l (percentage load) parameters. For Fedora/RedHat/CentOS it seems you have to compile it (source repository is here) with the following procedure: wget ...


1

#!/bin/bash # Array of root folders folders=("a" "b") # Search all specified root folders for f in ${folders[@]}; do # Descend hierarchy and retrieve modification date of each file with "stat" find $f -type f -exec stat -f "%m,%N" {} ';' | \ # sort by date, most recent first sort -gr | \ # extract first (most recent) file ...


0

With gnu you could try: find "$(pwd)" -mindepth 2 -maxdepth 2 -type d -printf "d%h\0%T@ %p\0" | awk -v RS="\0" ' /^d/ {directoryname=substr($0,2)} /^[0-9]/ && (!lmtimes[directoryname] || lmtimes[directoryname] < $1) { lmtimes[directoryname]=$1; lmtimedns[directoryname]=substr($0,index($0," ")+1); } END {for (directoryname in ...


1

Grouping and back references were the trick. Thanks for the push in the right direction. In the end, I used the following: sed 's/\([A-Z][a-z]*\)\([0-9][0-9]*\)/\1<sub>\2<\/sub>/g' file This tolerates the cases where a header, e.g. h2, occurs in the document.


0

This is NOT a case of "Flagecheck variable is not being identified inside IF test", it is a case of "$flagcheck is not a number, it contains a header line and other junk". It looks to me as if the sqlplus command is returning three lines, so $flagcheck actually contains this: FLAGCHECK ---------- 1 (with the 1 possibly right-justified rather than ...


3

Since you mention there may be false positives to manually correct later, you may want to consider a slightly more robust form which incorporates the following restrictions: All chemical symbols start with an uppercase letter. All chemical symbols are either a single uppercase letter or a single uppercase letter followed by a single lower case letter, ...


0

For those on Linux who are comfortable installing Python packages, I just released a nootify-send-headless program which is working well for me. It searches /proc for the required username and environment variables and then runs notify-send with these variables (it will use sudo to switch to the required user if necessary).


4

E.g.: sed -r 's:([A-Za-z])([0-9]+):\1<sub>\2</sub>:g' should do the job. (Match a letter followed by a group of digits and remember it as \1 and \2. Replace all of that by the same letter (\1) plus the digit group (\2) enclosed in the sub tag.)


0

Another approach is to configure PolicyKit to allow members of a particular group to reboot; that is, being authorised directly thus avoiding the whole question of satisying authentication to gain the superuser's authorisation. Create a file /etc/polkit-1/localauthority/50-local.d/50-local.pkla and add a clause like: [Allow reboot by booters group] ...


1

Use exec bash at the end A bash script operates on its current environment or on that of its children, but never on its parent environment. However, this question often gets asked because one wants to be left at the bash prompt in a certain directory after the execution of a bash script from another directory. If this is the case, simply execute a ...


1

First some comments/questions to get you thinking in a different way: (in other words, this started as a comment but became an actual answer somewhere along the way) Why are you even trying to extract the devicename element when you already know it - it's what you used to fetch the XML (with name=devicename in the URL)? Even if you didn't already have it, ...


1

.bashrc is sourced by default. -bash-4.1$ echo 'echo I was read' >> ~/.bashrc -bash-4.1$ script asdf Script started, file is asdf I was read bash-4.1$ exit Script done, file is asdf


1

I found your problem. The -A".html" restricts it to only accepting files that end in .html. If you remove that section, you will start to download all of the files. wget -w5 -r -nd -e robots=off -U mozilla http://wwwnc.cdc.gov/travel/yellowbook/2016/table-of-contents Edit: If you want to exclude js/css/etc files, then you'd be better off using -R to form ...


2

Yes setfacl should do it. Try the below, does it work ? setfacl -m u:user:--- file Where: -m is to modify the file/directory ACL user is the username for which you want to change permission --- will be the no permissions, replacing r,w,x file is the name of the file for which you want to change permissions


0

You can use trap in a script to intercept signals and perform some action such as incrementing a counter, displaying a message, etc. See Traps in bash guide for beginners


0

I've used a fullscreen xterm running a script to disable it when a key is pressed. But it's a screen saver taking all of my CPU. Not really optimized x)


0

You may make take the advantage of OBJECT IDLETIME command, which returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations). example code as follows: #!/bin/sh redis-cli -p 6379 keys "*" | while read LINE ; do val=`redis-cli -p 6379 object idletime $LINE`; if [ $val -lt $((30 * 24 * 60 * ...


0

I faced some similar issue recently, and I noticed that lftp[1] does the job nicely with wildcards. The systems I'm working on are vanilla redhat boxes, so I could imagine that this command could be available for you, too. [1] http://lftp.yar.ru/


2

If you absolutely have to clean a log file, you have to do it as sudo/root and restart the syslog daemon. The adm group only lets you read but not write (some) log files. Be aware that in a Unix system a file only give up the space being used/cease to exist when it is not used anymore, hence the need for a syslog restart because if you are deleting a file ...


1

Probably the script author wanted to make absolutely sure that the rm command was not modified by any existing alias statement. The author could also have accomplished this by using the absolute path /bin/rm instead of rm. RM="/bin/rm" $RM $FILE ... Why the author chose to redirect rm to STDERR eludes me, since the rm -f option does the same thing.


1

Perl is probably the best language for this kind of work. Perl's primary author, Larry Wall, is both a unix programmer and a linguist, and the language strongly reflects his interest in linguistics. There are numerous perl modules for language processing as well as simple text processing. For example, Lingua::Sentence which is a perl module for splitting ...


1

AFAIK, it will not be possible to copy files from (s)FTP using wildcards. Though, you can achieve the desired things by mounting the (s)FTP locally by using curlftpfs. You can use wildcards then from locally mounted drive


0

It doesn’t make sense to say “Handle the members of this group one way, and handle the members of this other group this other way.”  You should specify one group to handle one way, and say that everything else is handled the other way.  So I’m going to assume that you want all printf statements commented out except for ones that look like one of the ...


4

It should be possible with a single awk command awk '{print $1 > $2".lst"}' xxx.lst


2

You can do something like this: #!/usr/bin/env bash while read var1 var2; do echo "$var1" > "$var2".lst done < xxx.lst


1

Since jasonwryan hasn't turned their comment into an answer, I'll put this here just to close the question. If you prefer one of the answers from Wildcard's link instead, we can close this Q as a duplicate. for dest in file1 file2 file.3rd do tail -n 5 /path/to/source/file >> "$dest" done ...where 5 is the number of lines to grab. I put a loop ...


1

Use systemd-cat. It connects a pipeline or program output with the journal. Example: printf "Write text to the journal" | systemd-cat Result: journalctl -xn [..] Apr 12 13:37:00 servername [31509]: Write text to the journal If you want to identify the logging tool you can add the -t option: printf "Write text to the journal" | systemd-cat -t ...


0

if [ $( $2 or 0 ) xor $( $4 or 0 ) ]; then echo true; else echo false; fi Explanation: Based on the logic table that is an XOR operation so using $2 and $4 (the second and fourth arguments which have the data we need to do this operation) of course this doesn't account for when someone switches -a and -b.


0

in the menus of Terminal.app use Window->Merge all windows.


0

This was a requested feature in the original iTerm six years ago, but the only activity on it was to set the priority to low. From poking around in itermocil, I think you should be able to do it to either Terminal.app or iTerm(2) by using AppleScript. However, I know very little about AppleScript and can't find any real documentation on it.


1

If you are not restricted to wc, you can filter out the numbers with a tool like sed and then count the words using wc. Given your text (in testfile) will give: $ sed -e s/[0-9]*//g testfile disobediently RESINY GRAPHICS lownesses prickers intractabiliti es villainously MINIS blinkering applicants TORPIDITIES subtexts apportioned carded ...


1

For: When the device starts Before the device shuts down You need to look at an init script. How you would implement this depends on what linux/unix distribution you are using. Do you know which one? You can usually find out by typing the following at the command prompt: cat /etc/*release If you are wanting to execute a script on SSH Login you want ...


1

I found out why by redirecting the output of the ps command to a file. If I run the script from a launcher, grep finds the script itself (which has "serviio" in its name) and so it doesn't execute the code inside "if". I fixed it by making what grep looks for more specific. The main cause seems to be that if the script is run directly from a terminal it ...


3

sed takes its input from stdin, not from the command line, so your script won't work either theoretically or practically. sed -i 1,10d $dr does not do what you think it does...sed will treat the value of "$dr" as a list of filenames to process. Try echo "$dr" | sed -e '1,10d' or sed -e '1,10d' <<<"$dr". BTW, you must use double-quotes ...



Top 50 recent answers are included