New answers tagged

7

ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k "${f%%mkv}mp4";&& rm "{$f}.mkv"; is a syntax error - you cannot have a && after a ;. It should just be ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k "${f%%mkv}mp4" && rm "{$f}.mkv";. Then, your $f already ends in .mkv, so the rm ...


0

Okay solved by adding $$ instead of one if there is better solution please post it as well.


1

If your process is already running you can put its execution to background. ctrl+z will stop the process, and bg will continue process in background


6

Another way, depending on the exact behaviour needed, is to use the pipefail option: The exit status of a pipeline is the exit status of the last command in the pipeline, unless the pipefail option is enabled (see The Set Builtin). If pipefail is enabled, the pipeline's return status is the value of the last (rightmost) command to exit with a non-zero ...


0

To split the history file into files by line split --verbose -l1 ~/.bash_history (do this on a copy in a separate directory) To add the shebang: for file in *; do sed -i '1i #!/bin/sh' $file done


1

Do not bother trying to find out how to write your history out to a file. Your Ubuntu system already does by default to the file ~/.bash_history. So it takes a simple cat ~/.bash_history to retrieve the contents of the file.


9

@steeldriver mentioned in the comments that PIPESTATUS might work. I tried it, and it worked well. Here's what I did: somecommand | grep --invert-match something if [ "${PIPESTATUS[0]}" != "0" ]; then echo 'Oops' fi It runs the command as before, but then I have an if statement to look at the PIPESTATUS array. I only care about the ...


2

This is a guide on how to disable Middle Mouse Paste on Ubuntu automatically on startup. It was previously a post asking for help, but now that I have learned how to do it, I will share how I did it. This uses a script I found in another post that clears the clipboard for your middle-mouse button, so that it doesn't get pasted when you click the scroll wheel....


0

Try this command: awk 'BEGIN {p=""} {if(p==$1) {print "matched"; p=$1} else {print "not matched"; p=$1}}' file1.log You get: not matched not matched not matched To skip the first line: awk 'BEGIN {p=""} NR>1{if(p==$1) {print "matched"; p=$1} else {print "not matched"; p=$1} }' file1.log not ...


1

Use a systemd path job to listen for changes to the file /var/lib/apt/periodic/unattended-upgrades-stamp That file gets touched when unattended upgrades completes operation. There is no data in the file; the touch merely updates the 'modified' timestamp in the filesystem.


2

You can mount the remote file system over ssh using sshfs command, then interact with it as if it were a local system. There is a man page here: https://linux.die.net/man/1/sshfs which gives the syntax for the command: sshfs [user@]host:[dir] mountpoint [options] Another tool in the wonderful ssh toolbox!


1

I didn't bother with renaming because I have a 1:1 match to the ID and can get to the volume files now, but this worked! From MRI file parent directory: tree -dfi > dir.txt; grep "t2" dir.txt > mriFiles.txt Tree kept the order of the directories. Grep found the directories of interest.


1

Filesystem Hierarchy Standard stated that Manual pages are stored in <mandir>/<locale>/man<section>/<arch> With <mandir> usually be /usr/share/man, and the man<section> that fits best with your case is man1: man1: User programs Manual pages that describe publicly accessible commands are contained in this chapter. Most ...


1

You can accomplish this with a simple for-loop #!/bin/bash mapfile -t < text.txt for ((a=0,b=1; $b<${#MAPFILE[@]}; a++,b++)); do [[ ${MAPFILE[$a]} = ${MAPFILE[$b]} ]] && echo ${MAPFILE[$a]} done > unique.txt


0

Not sure if "successive duplicate lines" is a key issue for you. If not then you simply need the Linux command uniq to eliminate duplicate lines in the file with: uniq -u inputfile.txt > uniqe.txt If, however, you are only interested in eliminating successive duplicates you can use awk: awk 'NR == 1 {a=$0; print} a!=$0 {a=$0; print}' inputfile ...


4

As already pointed out by Terrance, you need double quotes; otherwise, the $ sign is sent literally. Also, remove the double parentheses which ask Bash to do the calculation. In which case you wouldn't need to pipe to bc, but Bash only does integer arithmetic. So it should be either echo "$((calc))" # evaluated by Bash or echo "$calc" | ...


0

From: https://unix.stackexchange.com/a/155627/343966 You can use the ImageMagic package with the following command: identify -format "%w %h %f\n" *.png | sort -n -r -k 1 | head -n 3 -k 1 sorts on the widths, change to -k 2 to sort on the heights. -r reverse the sorting, outputting the highest width or height, remove it to get the lowest ones.


0

so the content of sh script is: gnome-terminal --tab --title='frontend' -e "bash -c 'cd path/to/repo && git pull && npm i && code . && npm run dev'"; gnome-terminal --tab --title='backend' -e "bash -c 'cd path/to/repo && git reset --hard && git pull -f && npm i && npm run dev'&...


4

Although gnome-terminal indicates that the -e option is deprecated, it still works in 3.40.3. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal. # Use “-- ” to terminate the options and put the command line to execute after it. Developers seem to forget that this is the only way to do what you want, i.e., automatically ...


1

According to the bug tracker of ffmpeg, there were changes in the newer versions. Since the release between 4.2.2 and 4.3.2, the handling of relative URLs have been fixed to make it compatible with the official recommendations. If there are bare file names in the concat script, the files are supposed to reside in the same directory (and of course protocol) ...


0

I think that because the monitoring utility can write its output to a file such as airodump-ng -c 6 -w /root/chan6 wlan0mon You could press Ctrl-C at anytime and be able to continue your analysis based on the data captured in the /root/chan6 output file.


0

Landscape doesn't currently have recurring jobs. Scripts are one-time operations which happen either as soon as delivered to the client machine or at a specific future time. You have a couple of options: create a cron job or systemd timer on the client machine. create a cron job to launch a script remotely from the landscape-api at regular intervals There ...


0

There are many ways to run a script at startup, but here is one way using cron. Create a script somewhere on your disk, say, /home/you/myscript.sh, and put the following in the script. This will be the commands that are ran every time you startup your computer, so double-check that they are correct. The first line (#!/usr/bin/env bash) tells Ubuntu to use ...


0

Creating a folder in /usr/local/share/ca-certificates and copying my ca cert to it worked for me (Thanks Roy Abernathy) Here is the relevant part of my playbook: - name: Create directory mycert in /usr/local/share/ca-certificates/ file: path: //usr/local/share/ca-certificates/mycert state: directory - name: Copy certificate to /usr/local/share/ca-...


3

Just for fun, since you are on X Using python (or a bunch of other languages) We can use signals from Wnck.Screen and Wnck.Window to keep an eye on the creation and/or state change of windows. This includes maximizing and minimizing windows. That's exactly what the script below does. Subsequently, it maintains a logfile, that will be updated if you create, ...


2

Yes, you can use a here-string: <<< "$variable" Your original_text must be single quoted, otherwise the variables will be replaced on creating original_text. $ original_text='Hello $name, please come here $date' $ export name="John" $ export date="tomorrow" $ envsubst <<< "$original_text" Hello John, ...


3

You have several issues: echo is error-prone; especially for strings you don't control it is better use printf. Your variables are not quoted. --> printf '%s' "$1" You save the password in cleartext to a file. Why ??? You should pipe to your hashing algorithm directly or you'll expose your password. If you do that, you don't need echo or printf ...


1

If you add your cronjob via sudo crontab -e, it will run as root. No need for sudo, use: */5 * * * * /bin/sh /home/rki/docker-compose-stuff/dokuwiki/backups/dokuwiki_backup.sh The default working directory should be roots $HOME, so usually /root. You can find $name.tar.gz there. But better to use absolute paths, e.g.: /bin/tar -zcvf "/home/rki/Backups/...


-1

To run cronjobs with full root environment use this command */5 * * * * su - root -c '/home/rki/docker-compose-stuff/dokuwiki/backups/dokuwiki_backup.sh'


1

The main reason I can assume is either the log path doesn't exist or you don't have permission to write to the log path. Try executing the command manually instead of the cron python3 /script/working/directory/Script.py > /script/working/directory/logs/LOG_"$(date +"%d-%m-%Y")".txt You will most likely see the error in your terminal.


0

The problem you are having is when you open a new shell or restart the current shell, your script will no longer be loaded in the new shell. So, what you need to do is: Open the parent shell Execute the first command Create a child shell within the parent script This child shell will be loaded with the new environment parameters Execute the second command ...


4

It isn't supposed to respond. It is doing exactly what it should: it reads the input and assigns it to the variable fileType. However, you then have a while loop which is checking the value of a variable that never changes: while [[ "$fileType" != "EXIT" ]]; Since the value of $fileType is set only once and before the while loop, that ...


1

You seem to be catching yourself in an endless loop. If the user did not type "EXIT", then the while loop will go on forever. Any additional text you type is just being echoed to the terminal.


1

If I am getting your question right then you can simply move back directories to home folder by opening your teriminal and doing this: cd ~/my_files mv * ../


6

Conversion to upper case can be done in Bash using: TEXT="foobar" echo ${TEXT^^} A rotation cipher could be implemented using tr, e.g rot13: echo $TEXT | tr 'A-Za-z' 'N-ZA-Mn-za-m' # sbbone rot5 would look like this: echo $TEXT | tr 'A-Za-z' 'F-ZA-Ef-za-e' # kttgfw A partial version without tr command: #!/bin/bash TEXT="AZ" for (( i=...


0

A suggestion on how to design your loop instead. #!/bin/bash while read -r; do (($REPLY > 0)) \ && echo "condition passed" \ || echo "condition failed" done < <( \ find . -mindepth 1 -perm -644 -user bac0n -group bac0n -printf 1\\n -o -printf 0\\n \ )


Top 50 recent answers are included