New answers tagged

1

It appears to be authority issue over ssh: DISPLAY and AUTHORITY An X program needs two pieces of information in order to connect to an X display. (Note that wmctrl is an X program, even if it accesses other processes' windows rather than creating its own.) It needs the address of the display, which is typically :0 when you're logged in ...


0

I tried the accepted answer, which did not work. What ended up working was to remove the service, and add the service back: sudo update-rc.d -f tomcat7 remove sudo update-rc.d tomcat7 defaults


-1

Maybe you can just go to that directory? For example: Python2: cd scripts/ && python ./mk_make.py Python3: cd scripts/ && python3 ./mk_make.py if you need to go back after the step: cd ..


1

You can improve it by: putting it in a while loop (if user enter other choice) have shorter options: #!/bin/bash while true do printf 'What video do you want to see? (1, 2) or quit' read video case $video in *1 ) xdg-open https://www.youtube.com/watch?v=xQ9MpPIs1jM;; *2 ) xdg-open https://www.youtube.com/...


2

The answer is that scripts were not identical as i thought. Firstly, i added logging of cron with this @midnight /opt/sas/system/cleansandbox.sh > .../cron.log 2>&1. There was #!/bin/bash - no such file or directory error. So the script contained extra carriage return at the end of the first line, which i detected using this $ head -1 ...


0

Using sed: sed "4i define(\RELAY_MAILER_ARGS', \TCP $h 587')dnl" {filename} to repalce the content of fole: sed -i "4i define(\RELAY_MAILER_ARGS', \TCP $h 587')dnl" {filename}


0

Most basic example vi test.sh with content: #!/bin/bash ./test2.sh vi test2.sh with content: #!/bin/bash echo "hi there" test.sh when executed will execute test2.sh (and expects it in the same path as test.sh).


0

Connecting various pieces together, I came up with an easily reversible solution for enabling and disabling source downloads. Enable source From cloud and Stéphane Gourichon's solution, with sed modified to ignore non-matching lines and the output redirected with sudo to a temporary file under sources.list.d/: sed -e '/^#\sdeb-src /s/^# *//;t;d' "/etc/apt/...


2

The command display - && sleep 5 && wmctrl -r ImageMagick -e 0,254,600,800,560 starts the display command, waits for it to exit, and then runs sleep 5 && wmctrl -r ImageMagick -e 0,254,600,800,560 if the exit status indicates success. You probably want display - & sleep 5 && wmctrl -r ImageMagick -e 0,254,600,800,560 ...


0

The environment in crontab is not the same as in the user mfg from command line. Change crontab entry as follows: 10 14 * * * su - mfg -c '/home/mfg/batch_scripts/batchupi/batchupi.sh' You can also adjust some environment variables in your crontab file # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.oCXlYZ/crontab installed on ...


0

Read man sudoers - it will let you grant passwordless access to a single command. Read man visudo, too. From the man page: PASSWD and NOPASSWD By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for ...


4

"\r" is how bash prints the Carriage Return character. ("^M,0x0B) that some other systems use as part of their End-of-Line marker ("^M^J", Carriage Return, followed by LineFeed). Linux uses only "^J" (LineFeed) at End-of-line. One way of clearing out the "\r" characters is through dos2unix, in the package of the same name. Another way is: tr -d "\r" <...


3

Add an echo after esac and before exit 0. That's because echo -n does not append a newline character, and as a result the cursor remains after the last output character. Otherwise, Change all the echo -n within the case...esac with plain echo. Normally, one uses echo -n only when they explicitly want to suppress adding a newline at the end of output.


2

One possible way to solve this task is to use the command eval in a way as this: #!/bin/bash for i in {1..5} do eval "var$i"="$i" done # Output the result for i in {1..5} do echo -n "\$var$i : " eval echo "\$var$i" done Sample output: $ ./cycle.sh $var1 : 1 $var2 : 2 $var3 : 3 $var4 : 4 $var5 : 5 However, I think it is better to ...


1

In order to be able to run the script simply by typing its name, the script should reside in a folder that is listed in your search path. The command echo $PATH will list your current search paths. When you type the name of an executable, the system searches the folders listed in the PATH variable in order to find an executable with the name you typed. If ...


2

Hello and welcome on Ask Ubuntu. Lucky you, your question does not require advanced knowledge at all! 1) Locate folders where executable are located To be executed with only its name, a binary file must be in one of the directories present in the PATH environment variable. The default directory for user executable files on Ubuntu is $HOME/bin. If it ...


3

You can make alias of the path to your script. Firstly, make your command executable by using chmod: chmod u+x myvpn.sh where u+x gives only the user(you) the permission to execute the script. Then make an alias in your .bashrc to make it persistent: alias myvpn='/path/to/your/script' Now you can simply type myvpn from anywhere to execute the script.


1

You could move your script to /usr/local/bin and make it executable with chmod 0750 myvpn.sh. This should allow you to run your script by just typing it's name. Just in case, make sure your script starts with #!/bin/bash.


0

there is a way to detect whether the folder contains a file that has not .png as ending and then to fix it by adding ".png" to the end. Just create an executable file by touch pngchecker make it executable by chmod +x pngchecker open any file editor, for example nano nano pngchecker and then insert the following code with any text editor. #!/bin/bash ...


4

You can use inotify-tools To install it, run the following command in the terminal: sudo apt install inotify-tools To use it to serve your purpose, please follow these steps: Create and edit a script file in your home directory by running the following command in the terminal: nano ~/File_Monitor.sh Copy and paste the following code into the editor ...


2

Given $ cat test.csv A,table,20191229 16:41:58 B,table2,20191222 16:41:58 C,table3,20191223 16:40:58 D,table4,20191228 16:41:58 E,table5,20191227 16:41:58 F,table6,20191226 16:40:58 then using Miller $ mlr --csvlite --implicit-csv-header --headerless-csv-output filter ' strftime(strptime($3,"%Y%m%d %H:%M:%S"), "%w") == "0" ' test.csv A,table,...


0

Read man date, and do something like: while read line ; do echo "line=$line">&2 din=$(echo "$line" | cut -d, -f3 | cut "-d " -f1) echo "din=$din">&2 dayofweek=$(date --date=$din +%a) echo "dow=$dayofweek">&2 if [[ "$dayofweek" = "Sun" ]] ; then echo "$line" fi done <test.csv 2>/dev/null Remove ...


5

First, your grep wont work if expiration date description is something like 'Expires on:' or 'Expiry Date:'. So, let's grep with a pattern like this : grep -iE 'expir.*date|expir.*on'. Of course this may have to be involved. head -1 is for limiting result to 1 line The grep will result in an output of like this: Expiry Date: 2020-08-10T07:47:34Z So we need ...


2

I appreciate this is an old question, but I found it searching for a solution, so I ended up writing one. It's a shell script that checks for internet connectivity, and logs any outages, along with the re-connected link speed. Feel free to grab it: https://github.com/TristanBrotherton/netcheck


0

SOLVED:Its been a very long time and I forgot the trick. Open files, go to the top of the screen and click on files, click on preferences, click behavior tab, under executable text files check run them. I am using ubuntu 18.04.3 maybe a little different in different versions.


1

Here is the solution I came up with thanks to the other answers given #!/bin/bash for f in *.mkv *.mp4 *.wmv; do if [ -f "$f" ] # does file exist? then dir=$(echo "$f" | grep -o "E[0-9][0-9]" | head -1) # extract first E## from filename if [ "$dir" ] # check if string found then ...


7

Before I go any further, I have to mention: use https://www.shellcheck.net/ - it will make debugging shell scripts much easier, and that's one of the tools I've used to answer your question. Now onto the actual problem. If you look at the error output, you've missed a double quote here: "Ref"'\t'dCount"' For exactly the same reason - large amount of ...


0

like I added to my question, the issue was because I didn't have force_color_prompt enabled in .bashrc. once I uncommented the line, the variables loaded properly.


0

This doesn't directly solve your problem but in my ~/.bashrc I print a horizontal line in between each command: This is accomplished by setting $PS1 in ~/.bashrc: Divider="" for ((i=0; i<$COLUMNS; i++)) ; do Divider="$Divider""─" done if [ "$color_prompt" = yes ]; then PS1='${Divider}\n${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\...


0

The issue is that even when checkwinsize is set, the $COLUMNS variable doesn't get set until a SIGWINCH signal is received. I'm not sure if it's the right way to do it, but this seems to work for me: kill -s SIGWINCH $$ HORZLINE=$(printf '⎼%.s' $(seq 1 $COLUMNS)) echo "$HORZLINE" [EDIT: you don't need -e since there are no escape sequences in the string.]


0

From the bash man page for COLUMNS, Automatically set if the checkwinsize option is enabled or in an interactive shell upon receipt of a SIGWINCH. So the key is "interactive shell". At a terminal type: printf '⎼%.s' $(seq 1 $COLUMNS) You get the line. Put that command into a file (myline), set the executable bit and try: ./myline Single char output. ...


1

flock(1) manages flock(2) locks, whereas dpkg and apt use fcntl(2) locks. The two types of locks are completely independent on Linux. I'm not aware of any shell tool to do the right lock type. To do what you want to do, write a Python script using python3-apt. This allows you to maintain a frontend lock throughout the operation, ensuring that stuff works ...


2

This should work #!/bin/bash website="xplosa.com" certificate_file=$(mktemp) echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/") date_s=$(date -d "${date}" +%...


1

One thing you could try is building an interceptor. Move the apt binary to another location (use which apt to find out where it is). Rename it to something like apt-old, then as root create a shell script in the location you originally had apt in, make it executable, and make it look something like this: apt-old $@ What this will do is automatically pass ...


0

You should pass some argument to your script See : https://stackoverflow.com/questions/18003370/script-parameters-in-bash An example script could look like this ytchandl.sh: #!/bin/bash # If no Argument found then don't proceed:exit if [ -z "$1" ]; then exit 1; fi ChanURL=$1 youtube-dl -f best --geo-bypass --write-description -civw \ -o "/home/$...


0

This command attempts to find HTTPS URLs associated with a current session of Chromium: Here I am finding unique strings containing the word https to get the history. strings to read string in binary files, grep to find the strings with https in them and sort -u to print only their single occurence strings $HOME/.config/chromium/Default/'Current ...


-1

OS: Linux Mint (I'm using 18.3) I struggled for ages with this, trying to find out how you can click (or double-click) an executable item and get it to run, without further questions. I looked at all the stuff under Nemo Edit --> Preferences. The answer is actually very simple, and set up for you... I don't know whether this applies solely to Mint. On the ...


0

For those who are interested, here's how I succeeded to make it working. I created a script : #!/usr/bin/sh while true do if [[ "$(xdotool getwindowfocus getwindowname)" =~ "Chrome" ]] then xbindkeys 2>/dev/null else killall xbindkeys 2>/dev/null fi sleep 0.5 done I run this script on login, when I switch to a ...


0

This was painful, but in the end, due to a complicated custom PS1 setup with custom colors, this is the only thing that worked for me: new_line() { printf "\n$ " } if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]$(new_line)' ...


0

Not sure about usbmount but here's the reason for a similar case: /etc/dhcp/dhclient-exit-hooks.d/ In that particular case, the hooks are executed by /bin/dhclient-script as source (ie with .). run-parts is only invoked to get the list of scripts in that folder. run-parts --list /etc/dhcp/dhclient-exit-hooks.d/. Long story short, the scripts have to be ...


0

If your filenames do not have spaces, newlines or other strange characters, try this: for file in $(find '/home/username/Videos/' -type f -size +3G) do ffmpeg -i $file -c:v libx264 -c:a copy -vf [your_parameters] -preset [presetname] -crf 24 -b:v 400k ${file%%.mkv}.mp4 done -c:a copy is the same as acodec copy. You don't need it repeated.


1

Instead of using external commands like wc, expr, cut, you can and should use bash internal string manipulation commands. Also, your script is suited to use bash arithmetic operations. So, I have revised your script as shown below. See also my comments in the script. #!/bin/bash echo -n "Enter a string > " read str #len=`echo $str|wc -c` #len=`expr $...


1

I know this is an old question but i faced this similar issue and i used Ubuntu's key ring to solve it. Here is a solution on ubuntu 18.04LTS Open the terminal Write down keyring set {{service}} {{username}} for example if you are using this for school password logging: keyring set school mohamed It will log you for a password enter the password. Now the ...


Top 50 recent answers are included