Tag Info

Hot answers tagged

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 ...


9

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):


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:


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 ...


7

Answering to the third question: of course it can be used meaningfully in the way at Bash manual clearly hints – in a trap, e. g.: $ trap 'echo ‘$BASH_COMMAND’ failed with error code $?' ERR $ fgfdjsa fgfdjsa: command not found ‘fgfdjsa’ failed with error code 127 $ cat /etc/fgfdjsa cat: /etc/fgfdjsa: No such file or directory ‘cat /etc/fgfdjsa’ failed with ...


5

Now that Q3 has been answered (correctly, in my opinion: BASH_COMMAND is useful in traps and hardly anywhere else), let's give Q1 and Q2 a shot. The answer to Q1 is: the correctness of your assumption is undecidable. The truth of neither of the bullet points can be established, as they ask about unspecified behaviour. By its specification, the value of ...


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 ...


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.


3

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 ...


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. ...


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 ...


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 ...


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 ...


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" ...


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 ...


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 ...


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 ...


1

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


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

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


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

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 ...


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

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 ...


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.



Only top voted, non community-wiki answers of a minimum length are eligible