New answers tagged

0

Using bash release 4 or newer. On macOS, this may be installed via the Homebrew package manager, as the default bash is too old. # Make glob patterns disappear rather than remain unexpanded # if the don't match (nullglob). # Make glob patterns also match hidden names (dotglob). shopt -s nullglob dotglob # Create an associative array that hold the number of ...


5

FILTER=" | grep -v \"test\"" Operators like | don't have their special meaning when they're the result of expansions. Same for quotes. Make a function to hold the filter, the quoting is easier too: filter() { grep -v "test" } files=$(find . -type f -regex ".*$ext" | filter) Note that if you use find from command ...


7

When the shell reaches the "expansions" stage, control operators (such as |) have already been identified. The result of expansions is not parsed again in search of control structures. When the command substitution in files=`find . -type f -regex \".*$ext\" $FILTER` is expanded, Bash parses it as a simple command (find) followed by ...


0

Not looking too carefully at your code but suggesting that you use find instead: #!/bin/sh topdir=/Volumes/ARC-RAID/STORAGE/ASSET-Processing/Movies/LANDSCAPE/BRAND-RECOVERED/BRAND-RECOVERED-LANDSCAPE find "$topdir" -name 00error -prune -o \ -type f \( -iname '*.mp4' -o -iname '*.mov' \) \ ! -exec ffmpeg -i {} -f null /dev/null \; \ -...


0

To get the date in %Y-%m-%d format for all the Mondays in a given year, you can do: year=2021 ksh93 -c ' printf "%(%F)T\n" {1..53}"th Monday in January $year" | grep "^$year"' (note that some years have 52 Mondays, and some years have 53). To get that in %m-%d format and create a directory for each, you can pipe that ...


0

With your additional information, I am fairly confident the following is a solution: for SPEC in * do cd "$SPEC" eddy --main="${SPEC}.nii" \ --mask="${SPEC}_mask.nii" \ --index="${SPEC}_index.txt" \ --acqp="${SPEC}_acqp.txt" \ --bvecs="${SPEC}.bvec" \ ...


2

You could make this shorter, but my goal was to make it understandable not short. I also assume you want all the Mondays of a given year, not the next year's worth of Mondays, and that you are on a GNU system or at least have access to the GNU implementation of date in addition to the GNU shell. #!/bin/bash year="${1}" if [[ "${year}" =...


4

#!/bin/bash for n in {1..52}; do mkdir $(date -d"$n+monday" +%m-%d) done OUTPUT: 03-01 03-08 03-15 ect. This is will print the month-day for each Monday for the next 52 weeks but can easily be changed to any number of weeks.


1

You can rely on the date command. $ mkdir $(date +"%d-%m-%Y") Sample output: 27-02-2021 You can then run this command once every week using a cron job. For example, run this command every monday morning at 6am.


0

This routine will continuously run try.sh every second unless it is already running. If already running, it will pause until the former execution ends. loop_script.sh: while true; do if [[ ! $(pgrep -x /path-to-script/try.sh) -gt 1 ]]; then /path-to-script/try.sh fi sleep 1 done Execute this way: nohup /path/to/loop_script....


0

sudo apt install dbus-xll nano /root/.bashrc after alias l='ls -CF' , add this line alias='sudo /root/lscript/l' and install lazy script again


1

Using the perl-based rename command, you could capture everything up to the # the # and one or more following digits then optionally match but not capture one or more dashes; then substitute the captured substrings back in the opposite order: $ rename -n 's/(.*)(#\d+)-+/$2 $1/' *.mkv rename(Balisong Tutorial - (0g Chaplin) - Advanced #21-d8ajkHL34s0.mkv, #...


0

The select construct won't quit until a break command is executed. So after each action is completed, use the break command: case $opt in "CPU Stress Test (local)") sleep 2 cpu cleanup break ...


0

You have to get the crontab job access to some environment variables.. I just solved this probleme in my Kali Linux, so open terminal and type export hit enter and a message with info of the variables will show up.. get to the line where declare -x DISPLAY=":1" exists (value may be 0 not 1) just copy the DISPLAY=":1" and past it in your ...


1

The error message basically says what the problem is, "1900m" is not recognised as an argument to '-L', and the man-page for tar explains it. You (quite sensibly as "m" is the prefix for "milli", which doesn't make sense with bytes) must use a capital "M" when you want to specify a number of megabytes (taractually uses ...


1

If you can run GNU tar, the options --tape-length=N and --new-volume-script could be used. Your command to create the volumes would be something like this: tar cvf volume /path/to/files --tape-length=1945M --new-volume-script=/path/to/script.sh And to extract everything from them: tar xvf volume --new-volume-script=/path/to/script.sh For the new volume ...


1

You can use tar in combination with split to achieve this: tar cf - aaa/input | split --bytes=1900m --filter='gzip > $FILE.gz' --numeric-suffixes - ./Log- This command creates a tar archive to stdout and pipe the output to the split command which will split on every 1900MB, filters the data through gzip, uses stdin as input (the -) and places the output ...


0

I think, it is better to use the --spider argument with the wget tool. It also works on lightweight versions of the wget tool (in BusyBox). Example: URL="http://www.google.com" if wget --spider "${URL}" 2>/dev/null; then echo "OK !" else echo "ERROR ! Online URL ${URL} not found !" fi


0

Here is a concrete example stdbuf -oL ./a.out > log.txt Only when stdbuf is used, the printout can be piped into file.


2

No, the problem is that (by using \") you're telling ffmpeg to transform a file "Accepting Amendments.mp4", with quotation marks contained in the name. That file doesn't exist, so ffmpeg fails. What you really want to do is use unescaped quotation marks that the shell interprets as "don't split the contained value": ffmpeg -i "$...


0

$ cd /path/to/DATA/AAA/INPUT $ for file in *; do tar cf ../OUTPUT/"${file}".tar "${file}"; done


0

By refreshing credentials in the background: #!/bin/bash configurePermissions () { sudo -v refreshPermissions "$$" & } refreshPermissions () { local pid="${1}" while kill -0 "${pid}" 2> /dev/null; do sudo -v sleep 10 done } configurePermissions


0

It may look ugly but using find to get files is the most robust method, avoiding issues with spaces & other special characters in names. You get a list of modified times + files, sort it by recent, get the top n (here 5), drop the times leaving only filenames, and pass it to your script: find dir -iname '*.txt' -printf '%T@\t%p\0' | sort -znr | head -z -...


0

I had a remotely similar problem: I put a server in the garage so that external backups are stored in a location remote from the house. (Should the house burn down, a backup would be in the remote garage.) The volumes on the backup server were encrypted with VeraCrypt. The password was stored on the main server in the house. When the backup server booted, it ...


0

I don't know if this can help, but - since the question is a bit old - hope this can at least provide some help to the future readers: This command finds(the name of the actual command is find) every file with the *wildcard [dot]extension at the end of it. find . -name <*.Extension> -type f -exec < command > {} \; where: . or - ./ is marking ...


1

Run it as a service. Create /etc/systemd/system/myscript.service: [Unit] Description=My Script [Service] ExecStart=/usr/bin/python3 /path/script.py [Install] WantedBy=multi-user.target Then run it with: sudo systemctl start myscript # Runs the script now sudo systemctl enable myscript # Sets the script to run every boot There are lots of other ...


0

There are multiple ways to do this based on your needs and conditions such as user privileges and the order of execution whether it should wait for other services to start or not. the easiest ones are : crontab can be used like the following: #crontab -e @reboot python /path/your_script.py & Or you can mention the the command in /etc/rc.local this ...


1

Here is a short bash script I have written that will accomplish generally what you need. This will only check the current day and 2 days into the future as that is what wttr.in returns by default but I'm sure you can find some option to expand it if needed. You may have to play with the mail sending part of the script depending on the system you are ...


2

Expand your regular expression to include the entire string, and use the -o option to only print the match. Read man grep. grep -E -o ',[^,]+,400,Bad Request' Test.jtl


0

Your first script is looping through $@, if you want to add an operand, you can save the first argument (op=$1) and then use shift. from man bash: shift [n] The positional parameters from n+1 ... are renamed to $1 .... Parameters represented by the numbers $# down to $#-n+1 are unset. n must be a non-negative number less than or equal to $#. If n is 0, ...


2

When you do for sum in $@ what's happening is that the variable $sum is being set to each value in turn. You can see this with a simple test for lp in $@ do echo $lp done If you run this with "10 20 30 40" as parameters then you'll see it output each value in turn. So what you need is a loop with a temporary variable and a sum of the values sum=...


0

If I understand you correctly, contents of file.txt is something like abcde 12345 abc 5a3bg2 gdrr something etc., and you want to create folders a0_12345, a0_5a3bg2, a0_something etc. So I would use: awk '{ print "mkdir a0_" $2 }' file.txt | bash It doesn't even have to be in a script, if you need to do this only once. Just type the above ...


0

Gentoo is one of the best documented distributions. Try searching on the internet first and then ask questions here. For your question I can recommend these Gentoo wiki pages: Topic Link Xorg https://wiki.gentoo.org/wiki/Xorg/Guide Display Manager https://wiki.gentoo.org/wiki/Display_manager SDDM https://wiki.gentoo.org/wiki/SDDM Bash https://wiki....


0

The line ending problem isn't directly related to the character set, e.g. "code page 1252" used by Windows has the carriage return (CR) and line feed (LF) characters, the same as UTF-8. (And, since EBCDIC was mentioned, it also seems to have both, plus another newline symbol.What weirdness systems with it actually use is another thing entirely.) So,...


0

I only read the first few lines (too long). But the \r indicates that you are editing on an MS-Windows machine. MS-Windows does line endings in an incompatible way (\r\n). Other systems do (\n). Solutions: Don't use MS-Windows Use an editor that can be configured to use the correct line-endings. Put the file through dos2unix when importing.


7

As you have correctly mentioned, the IFS (field splitting) environment variable plays an important role here. Normally, IFS is set to include <space>, <tab>, and <newline> characters. It means when no quotes are used on a variable, the shell interpreter will break it into separate arguments by IFS values whenever possible (it even squeezes ...


0

you can allow root access only with tagged ssh public key aithentication : in /etc/ssh/sshd_config, set PermitRootLogin forced-command-only Force-command is a command you tag public key in /root/.ssh/authorized_keys such as command="script_you_have_strictly_controlled" id-rsa <public key here> This way you have a controlled elevation to do ...


0

Either your admin user on 192.168.2.250 needs to be able to sudo to the correct user, for example ssh sudo id or you could set-up ssh-ing to a user that is allowed root access to the machine, so ssh root@192.168.2.250. If you're alone on your home network, both should be OK; in a corporate environment, you should look at the security implications.


-2

NOTE: the task described in the original question can be achieved in a safe way using sudo and sudoers configurations. This answer is going to stay for people that are still committed in running scripts with setuid, also after being warned of security implications. The method described also put bases for writing a more robust treatment of environment, like ...


2

grep -rlZF -- "$oldstring" /home/commons.bundle.js | xargs -r0 sed -i "s/$oldstring/$newstring/g" -- The following minor changes should make it work: grep should use -F so that the strings passed are not evaluated by grep as regexes. Another grep option to use is -Z which will pass filenames onto xargs using the null delimiter. At the ...


Top 50 recent answers are included