Tag Info

New answers tagged

0

/etc/environment takes a proper re-login to take effect, because it is processed by PAM at login. Further, as @przemo noted, it is not run or sourced as a script, so variables are not expanded. Put such variables in a .sh file in /etc/profile.d/: sudo tee -a /etc/profile.d/my_vars.sh <<"EOF" M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1 ...


0

/etc/environment is not a script file, you cannot use variables, for further reading I recommend https://help.ubuntu.com/community/EnvironmentVariables


1

A version that is a bit more 'general' - should work with a varied environment: (depends on terminfo) Insert this in your $HOME/.bashrc function fgtab { echo "tput setf/setb - Foreground/Background table" for (( f=0; f<8 ; f++ ));do for (( b=0; b<8 ; b++ ));do echo -en "$(tput setf ${f})$(tput setb ${b}) $f/$b "; done; echo -e ...


0

Another approach with awk: awk '{ if ($1 == "string") name = $4; else if ($1 == "fun:") print name " " $2; }' your_file Assuming that "string name" and ":" are separated by space and "fun" is always followed by ":" without space.


1

I came up with this solution: open ~/.bashrc in an editor copy this and add it at the end of .bashrc file: PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] ' save the file and restart bashrc: source ~/.bashrc For a full list of available colors and further options look up these links: ...


0

#!/bin/bash RE_NAME='^ *string name *:' # regex for the 'name' line RE_FUNSTART='^ *[{] *$' # regex for the start of the 'fun' block RE_FUNEND='^ *[}] *$' # regex for end of 'fun' block RE_FUN='^ *fun:' # regex for 'fun' line while read line; do if [[ $line =~ $RE_NAME ]]; then name="${line##*: }" echo elif [[ $line =~ $RE_FUNSTART ]]; then ...


1

I had the same problem but was not very happy with the solutions here or the solutions did not work for me. What I found out to get it running is to send a NULL input to apt-get, so that it continues to work. It looks like this: apt-get -y install gcc g++ make cmake perl < "/dev/null" cd ~/ mkdir t1 cd t1 #newline Hope other people can use this ...


0

Your string CD1243423kk,0dc3dopwlz doesn't pass the if statement: if [[ ! $input =~ ^[a-k][a-kC-Z0-9]{4,},[a-z0-9]{3,}$ ]]; then echo "Errore Autenticazione"; exit 21; fi Fix that and you fix your problem. Remember that it's case sensitive. The first group needs to be [a-kA-K] and then your string will pass.


2

Well you could use cron with a silly little script to check /var/log/auth.log every 10 minutes. If you set it up correctly, cron will email output wherever you like so we just need a script to run: #!/bin/bash cat /var/log/auth.log | perl -MDate::Parse -ne ' print if /login|ssh/ && /^(\S+\s+\d+\s+\d+:\d+:\d+)\s/ && str2time($1) > ...


0

Because my status-old was too problematic even with apt-get update, This worked pretty well for me: (as root) cd /var/lib/dpkg cp -avf status status.corrupt tr -cd '\11\12\15\40-\176' < status.corrupt > status This command uses the -c and -d arguments to the tr command to remove all the characters from the input stream other than the ASCII ...


0

In my .bashrc, I define a function, screenshot to use ImageMagik: screenshot () { import -window root ~/var/screenshot/$(tshhmmss)_screendump.png } and, for the timestamp, alias tshhmmss='date +%y%b%d-%H%M%S' Then, wrapping it in while sleep 5 ... is easy.


1

Yes: #! /bin/bash while sleep 5 do shutter -f -o 'myshot-%T.jpg' -e done The sleep command can take various time durations as arguments: 5s (or just 5) for 5 seconds, 129m for 129 minutes, etc. The shutter command supports JPEG output, and the %T tells Shutter to automatically replace that part with the time of the script. (There's also %NN to ...


0

While calibre can do it, it takes >100M to install and unoconv has most of components installed if you have LibreOffice/OpenOffice. sudo apt-get install unoconv --no-install-recommends unoconv -f txt *.fb2


0

Ok, I've found a solution! 1) Running a script.sh while the notification is comming (possible with KDE, menuK->configuration->notifications) 2) The script .sh is: #! /bin/bash exec >/home/guillaume/ver-XBMC.log 2>&1 python /home/guillaume/ver-XBMC.py 3) The python script: #!/usr/bin/env python # coding: utf8 import psutil import subprocess ...


0

Use vimdiff... Normal syntax : vimdiff file1 file2


4

No it isn't. As you said, man sim doesn't exist. And running sim gives No command 'sim' found, but there are 23 similar ones In your example 'sim' was only used as part of a file name. 'fun-sym' could have been almost anything, it has no effect on the command. Since it is only the file you are creating, it only has to be a valid file name. All that ...


0

You could try to change synclient touchpadoff=0 to synclient touchpadon=1 and at right" styles rotate half and erase" rotate half. and it might work fine this way.


-1

Change the script to xrandr|grep " connected" |awk '{print $5}' as Charles suggested.


0

An inventive use for $BASH_COMMAND Recently found this impressive use of $BASH_COMMAND in implementing a macro-like functionality. This is the core trick of the alias and replaces the use of the DEBUG trap. If you read the part in the previous post about the DEBUG trap, you’ll recognize the $BASH_COMMAND variable. In that post I said that it was set to ...


2

You can have charmstore at GOPATH=/home/sajith/Projects/Backup/charm-store-server/charmstore as you have written, however, then you need to change GOPATH for any other project. I would recommend setting the GOPATH to: mkdir /home/sajith/Projects/Backup/go export GOPATH=/home/sajith/Projects/Backup/go mkdir $GOPATH/src Do the go get -u -v -t ...


1

This sounds suspiciously like a homework assignment*, but here we go. Why would you source the ELABORATO.SH script? If you do and it has an exit statement or errors out, your TEST.SH does the same. I don't think that's what you want. I would just run the script: bash ELABORATO.SH param1 param2 Did you think about redirecting its input? bash ...


3

When you call the script, a new child shell is invoked to run it. Its proxies are set, but the proxy of the parent process (your shell) can't be changed from a child process. Try sourcing the script, i.e. call it like . setproxy 21 Then the script will be interpreted by your current shell.


1

How about while server-is-not-running; do try-and-start-server sleep seconds-to-wait done where server-is-not-running is your current test to see if the server is running, i.e. a shell function or an external command returning non-zero if the server is running (alternatively, ! server-is-running if that function or command returns zero if the ...


1

Just make an infinite while loop: #!/bin/sh while [ TRUE ]; do check_server_status 10.0.. etherwake ff:ff.. done


-1

Does the file exist and do you have read permissions on it. Is it executable, it's directory path needs to be executable. The commands ls -l and chmod will help. Secondly your terminology is a bit microsoft, sh files which execute more like .bat files and binaries which ms calls .exe.


1

Assuming you wish to run this script every time your machine boots, a convenient way is to add an upstart init task. Create a file my-startup-script.conf (its name is up to you, but it must have extension .conf) in /etc/init, containing the following: description "Describe what the script does." start on filesystem task script cd /path/to/script ...


1

Meld is a really great tool. But you can also use diffuse to visually compare two files: diffuse file1.txt file2.txt


0

I then tried this: sudo chown root:root ~/ got no output and then sudo chmod -R 777 ~/ That pretty much solved my problem but for two files which returned chmod: cannot access `/home/leo/.gvfs': Permission denied chmod: cannot access `/home/leo/.config/google-chrome/.com.google.Chrome.Z07tM9': No such file or directory.


0

I suggest you set the correct executable search path when invoking your program: export PATH="/myownbing:$PATH" cufflinks Or shorter but without altering the environment of the executing shell: PATH="/myownbing:$PATH" cufflinks


3

Litteraly sticking to the question (file1, file2, outputfile with "has changed" message) the script below works. Copy the script into an empty file, save it as compare.py, make it executable, run it by the command: /path/to/compare.py <file1> <file2> <outputfile> The script: #!/usr/bin/env python import sys file1 = sys.argv[1]; file2 ...


9

Or you can use Meld Diff Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems. Install by running: sudo apt-get install meld Your example: Compare directory: Example with full of text:


2

Your install script could be failing for multiple reasons: If the group does not previously exist the useradd command will throw an error: useradd: group 'coolgroup' does not exist The solution to this problem is to make the group before calling useradd. If the parent directory of the user home ($dir in your example) does not exist the useradd command ...


10

Look into the diff command. It's a very powerful tool, and you can read all about it by typing in your terminal man diff. The command you'll want to do is diff File_1.txt File_2.txt which will output the difference between the two and should look something like this (sorry for the lack of cropping):


1

Since your script runs as root, you can also use sudo to change to the other user on a per-command basis. This may be a bit more cumbersome than rcj's suggestion, but it should work. Another possible advantage is that you still deal with only one script, as opposed to two/several with the other solution. mkdir -p $dir useradd -d "$dir" -s "$bash" -g ...


2

The use of 'su - "$user"' in your script will end up starting an interactive shell for the specified user. You could use the '--command' option to 'su' to specify a command to run. Then you would encapsulate the commands you want run as that user in a script which could be created as a bash here document. Your script would look like this... mkdir -p $dir ...


0

This awk command should do the trick, awk '{if ($1) {$1=strftime("%c",$1); print}}' /var/lib/misc/dnsmasq.leases Old version which would dump the Unix epoch on empty lines: awk '{time=$1; $1=""; print strftime("%c",time) $0}' /var/lib/misc/dnsmasq.leases The trick is to apply strftime only to the relevant argument and print everything else as is. I ...


1

You could try the below awk one-liner command, awk 'NF{ $1=strftime("%c", $1);}1' file OR $ awk 'NF>1{ $1=strftime("%c", $1);}1' file Monday 22 September 2014 06:54:14 AM IST 08:11:96:e9:52:ec 192.168.1.96 W11837894 * Tuesday 23 September 2014 12:48:48 AM IST b4:b6:76:0c:c9:4d 192.168.1.46 root-HP-9470m * Sunday 21 September 2014 07:00:16 AM IST ...


2

The dialog manpage mentions whiptail (in a rather deprecating fashion). It does not have the --ascii-lines option, but it does not mess up the screen either: The script: #!/bin/sh TEMP=/tmp/answer$$ whiptail --title "Administrative tasks" --menu "Tasks :" 20 0 0 1 "Display firewall settings" 2 "Restore firewall settings" 3 "Flush Firewall settings" ...


8

As already answered, these two lines are clearing the content of the /var/log/messages and /var/log/wtmp files, or are creating them in the unlikely event they do not already exist. However, they are based on a well established urban legend that gives /dev/null "paranormal" powers. It actually has none so cat /dev/null is a waste of keystrokes, time and ...


1

As McLovin says, the automatically set, readonly UID (and EUID) variable is a special feature of bash (and some other shells). It's not standard for Bourne-style shells and sh cannot be assumed to set these variables. In particular, sh in Ubuntu is (currently, by default) dash, which does not set them. You have two options: Cause your script to be run by ...


1

Use this in .bashrc : export xyz="/home/faizal/DEV/ADT workspace/xyz" Use this to access it : cd "$xyz"


1

pushd with no arguments swaps the top two entries on the stack, allowing you to effectively cd back and forth between them. Starting out in d1, execute pushd d2 adds d1 and d2 to the stack and leaves you in d2. Execute pushd again with no arguments, and you're back in d1 with d1 and d2 reversed on the stack.


0

Read command has an option to prevent input from showing when you type it. echo "Enter the password: " read -s password #Print the password echo $password


3

Instead of executing it with sh script.sh execute it with bash script.sh (or add #!/bin/bash as the first line to set the interpreter). The sh shell in Ubuntu is not bash, but a separate shell called dash. dash does not have as many features as bash, which makes it more efficient, but these missing features sometimes break scripts intended for bash. ...


26

Assuming the commands succeeded, /var/log/messages and /var/log/wtmp still exist but are now blank. Shell Redirection > is a redirection operator, implemented by the shell. Its syntax is: command > file This redirects command's standard output to file. file may also be a device node. If file doesn't exist, it is created as a regular file. If file ...


14

cat will list the contents of a file comming after cat to standard output and the > sends it to the file messages and wtmp where > means to first remove all contents of the file and >> would mean to ADD to the current file. In this case you are using > so the file will end up being empty. Now for the kicker: /dev/null is a device that sends 'nothing' to ...


5

> is output redirecting operator. It will redirect the output of command to file mentioned after it instead of standard output device, truncating or overwriting file's contents. for example ls -l > demo.txt. After executing this command, "demo.txt" will contain th output ls -l command. Now next thing is what is this /dev/null./dev/null is the null ...


0

It seems to be a unity bug. If you try to restart unity it works correctly. Hit Alt + F2 and type unity --replace to restart unity. After this, I think it will be OK.... :)


0

Radu's answer nearly worked. I had to set the path to make it work: #!/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin if [[ ! "$(service mysql status)" =~ "start/running" ]] then service mysql start fi


1

You can get the full modification timestamp (mtime date and time) in human-readable form from stat using the %y format specifier i.e. $ stat -c '%y' file 2014-08-21 12:30:03.449771375 -0400 I don't think stat itself has a format specifier for just the date portion of the mtime, but with GNU date you could re-format the epoch seconds from stat like $ date ...



Top 50 recent answers are included