Tag Info

New answers tagged

0

Note that any use of sudo on the system will already be logged in /var/log/auth.log. That file also contains other authorization-related information (see more details here about log files). Sudo also logs more than just the timestamp, but also the user who invoked sudo, the working directory, and more. If you want to just extract the uses of apt-get install ...


1

Try xargs: xargs -L 100 echo < file Test: for i in {1..7000}; do echo "line $i"; done | xargs -L 100 echo


2

You need to set the IFS (Internal Field Separator) variable of bash to newline \n while creating array out of the variable so that each newline separated entry of the variable will be taken as an array element. In your primary script the array is being created out of the entries of variable separated on the default IFS value i.e. space, tab and newline. In ...


1

I think you had a little misunderstanding with the use of arrays. #!/bin/bash # Random lists picks # This is a script for picking random choices as a prediction. # Create array "things" things=('Walk' 'Song' 'Talk' 'Friend' 'Spontaneous act' 'Call') # Create array "effects" effects=('will bless you' 'will lift your spirit' 'is healthy' 'can help' 'will ...


1

I would do something like this: split -l 100 --numeric-suffixes--additional-suffix=.tmp The_Big_File fragment_ for f in fragment_[0-9][0-9].tmp ; do tr "\n" " " <$f echo rm $f done


0

I found the solution to my problem. I'll post it here so anyone who has the same problem won't get stuck. mypass=$(sed '2q;d' .auth) debconf-set-selections <<< "mysql-server mysql-server/root_password password "$mypass debconf-set-selections <<< "mysql-server mysql-server/root_password_again password "$mypass I didn't parse the type to ...


1

It is failing because the first argument to the script is missing. The 17th line contains: ./test_$1 > test_log 2>&1 The $1 indicates the first argument to the script. For example, if you run the script as: ./testandlaunch foobar The above line would become: ./test_foobar > test_log 2>&1 As you were running it without any ...


3

I was too quick on this one, your test works. I suspect you somehow have set $SCREEN_NAME either globally or previously in the script as a string containing an illegal character. ^[a-zA-Z0-9_.-]+$ matches a non-NULL string containing only the allowed characters, so if $SCREEN_NAME is a non-NULL string containing only the allowed characters, $SCREEN_NAME =~ ...


1

Using grep with PCRE [-P] and Dotall modifier [(?s)]: 1st portion: $ grep -Poz "(?s)^.*?(?=\nsegsites:)" file.txt // [297]((((21:0.125204,20:0.125204):0.00994299,(28:0.0790047,(7:0.0146105,5:0.0146105):0.0643943):0.0561423):0 2nd portion: $ grep -Poz "(?s)segsites.*?(?=\n[10]+$)" file.txt segsites: positions: 1 2 4 6 9 10 45 67 78 89 In case of ...


3

Well, in awk: awk '/^[01]+$/ {print > "third-file"; next} /(segsites|positions)/ {print > "second-file"; next} {print > "first-file"}' input-file Considering three cases: A line containing only 0s and 1s (/^[01]+$/) A line containing either segsites or positions: /(segsites|positions)/ All other lines In each case, we print to different ...


3

Came here late. Here is another python approach: #!/usr/bin/env python2 with open('/path/to/file.txt') as f: for lines in f.read().split('*'): entries = lines.rstrip().split('\n') for i in range(1, len(entries)): print entries[i] + entries[0]


3

Using only bash: #!/bin/bash today="$(date +"%b %d %Y")" while IFS= read -r line; do [[ $line =~ ^$today ]] && echo "$line" done </path/to/file.txt The today variable stores that day's formatted date while IFS= read -r line will read each line from file.txt and save it as variable line [[ $line =~ ^$today ]] will test if the line has ...


5

An easy way would be to use grep: date +'^%b %d %Y' | grep -f- your_file


4

The program you are trying to execute seems to be for the Windows platform. If you do a file programname.exe you will get information about the file. Example: file Setup.exe Setup.exe: PE32 executable (GUI) Intel 80386, for MS Windows This means it will not execute unless you have a working Windows system (dual boot, inside a virtual container or maybe ...


3

Through my favorite Python... with open('/path/to/the/file') as f: counter = False for line in f: if line.startswith('*') and not counter: m = line.strip().lstrip('*') counter = True elif line.startswith('*') and counter: counter = False elif counter: if not ...


6

Here's a Perl way: $ perl -lne '/^\*(.*)/ || print "$_$1"' file strawberry raspberry blueberry boysenberry blahblah blahblah blahblah strawberry blueberry blah vegetable pingpongtable Explanation The -n will cause Perl to read each line of the input file, saving it in the special variable $_, the -l will cause it to i) strip trailing newlines (\n) from ...


8

With parted, you can just add the -s option: parted -a optimal -s /dev/sda mklabel msdos From the Trusty man page for parted: [...] -s, --script never prompts for user intervention [...]


8

In sed, you could copy the "special" line into hold space before deleting it sed -e '/^\*/{h;d;}' and then append the hold space to each succeeding pattern space, replacing the resulting newline and marker character -e '{G;s/\n\*//;}' Testing it with your data, $ sed -e '/^\*/{h;d;}' -e '{G;s/\n\*//;}' file strawberry raspberry blueberry ...


11

This awk code could be enough: awk -F'*' 'NF == 2 {label = $2; next} {$0 = $0 label} 1' To break it down: Use * as the field separator. This way, we can simply examine the number of fields (NF) to determine if the beginning or end of a block is reached. When there are two fields, we save the second field in label and continue to the next line. From ...


3

Adding to heemayl's answer, it's worth pointing out that fg, bg, and jobs have to be built into the shell, because they manipulate data structures in the shell's memory and/or the kernel state associated with the shell's process. It would not be possible to write an external command that does what fg does. Other commands that have to be built in include ...


32

You are not getting any files against those commands because they are shell (bash) built-ins, not separate executable files (e.g. binary files, scripts). Actually, shell built-ins are compiled into the shell executable; if you want you can check the source code to be sure of it. As which or whereis only looks for external executable files, you are not ...


2

This are shell builtin commands. There is no binary for them as they are a part of Bash (or whatever shell you are using). They are documented for example in the Bash manpage (see the section "SHELL BUILTIN COMMANDS")


6

They are shell built-ins - you can get basic usage information by typing help fg or help jobs at the bash shell prompt, or more detailed information from the bash manpage.


2

fg, bg and jobs are not separate utilities, but they are part of bash(shell builtin commands). you can find more about them in bash manual using the command man bash


2

When a script is run using `source' it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. Syntax . filename [arguments] source filename [arguments]


3

Use this command: notify-send "$(more /home/tim/autest.sh | head -4 | tail -1)" When you use your script with a shortcut, more gives this: :::::::::::::: /home/tim/autest.sh :::::::::::::: #! /bin/bash Here is an excerpt from the source code of more.c while (fnum < nfiles) { if ((f = checkf (fnames[fnum], &clearit)) != NULL) { ...


1

Don't use cd. Use an absolute path: /<your_path_to_eclipse>/eclipse And if you have spaces in your path: ;) "/<your_path_to_eclipse>/eclipse"


1

$1 within a bash script is a reference to the fist argument passed from the command line, so you're actually trying to process a single folder. There are answers already about how to solve your problem using pure bash, but I'd like to add that if you need a better filtering of what is being processed you can use find with some options to select the files to ...


2

Taking the KISS approach, I would recommend the following script #! /bin/bash cd $1; rename 's/$/\.bu/' * This will change working directory to the first parameter and then add a .bu extension to all files. This nullifies the need of for loop. EDIT: If you want to change the extension(instead of just adding it), you can try rename 's/\..*$/\.bu/' * ...


7

#!/bin/bash cd $1 for f in *; do mv "$f" "${f%.*}.bu" done


3

Try that instead (assuming that $1 is a folder): for f in $1/*; do mv "$f" "$f.bu" done Or use the rename utility: rename -v 's/$/\.bu/' $1/* Those commands add an extension. If you want to change the existing extension use that: rename -v 's/\.[^\.]+$/\.bu/' $1/*


1

From what I see there is an error in the path name either in the desktop file or in the script itself. Try editing it. Insted of Cauldon Server use Cauldon_Server. Directory name shouldn't include space.


8

Depending on what you do and don't know about the output of pip will be before you run your cd command, you might decide to grep for something other than /usr.*. If you know the directory starts with /usr (and that it appears at the end of the line of output from pip, and that /usr does not appear anywhere on the line before the directory name), then that's ...


10

Use Bash's command substitution $(), you also need -o with grep to only select the matched portion: cd "$(pip install django | grep -o '/usr.*')" Note that although you will get away in this case but you should always enclose the command substitution with double quotes so that the shell does not perform word splitting on whitespaces (by default space, tab ...


0

The command more doesn't seem to work. Try changing each time it says more to cat. How did I solve it? I added this line after each if: notify-send Alert No1 changing the number 1 to another number each time I used it. This showed me that the if then else statements weren't running. I then decided to change it to cat, because I use that and know it ...


5

Since you want to learn bash internal source code, let's get it first with: apt-get source bash && cd bash-4.3 I'm running 14.04 and I now have a folder named bash-4.3. Prefer the apt-get source solution as it will apply all the patches that the Ubuntu package version provides. Now modify the following files: Index: bash-4.3/bashhist.c ...


1

First of all, install inoticoming: sudo apt-get install inoticoming Then use this command: Pay attention to ongoing processes of inoticoming, because they can be started multiple times. $ inoticoming /home/user1/watched /usr/local/bin/syncbh.sh /home/user1/watched/{} \; ^ ^ ^ | ...


1

Ok let's go... First of all: Script to watch the watched directory #! /bin/bash folder=/path-to-watched inotifywait -m -q -e create -e modify '%:e %w%f' $folder | while read file do #make the sync here done Second To make sync as another user (user2) the : sudo -H -u user2 bash -c 'sh /usr/local/bin/syncbh.sh ' Now In order to dont make ...


0

Try using the package from the repository, sudo apt-get install python-pip If this gives you errors, you might first want to do a sudo apt-get remove python-pip and then try again with install. This also shouldn't interfere or remove the modules you already installed.


4

Just to leave the answer here to those who are still chasing this. I guess I have learned my lesson in misunderstanding 256 color support in a way. So I found my answer here. To sum it up, themes like Gotham offers 256 support, and I had in mind that it would go both ways in terms of appearances (terminal and gui). This is not the case of course, one would ...


1

I guess the issue is with the -S if you try to omit the -S option, it should ,work, even without bash -c so try this screen -dm sed -i 's/a/b/'g some-file.txt That should work. BTW screen is not updated, you should consider switching to tmux. It can provide you with much more features. You can install tmux by typing: sudo apt-get install tmux So your ...


0

Personally I would execute the command to open pdf or other files in subshell, put a delay to let the files open, and then exit. Basically, here's what I've tested (nohup gnome-open *.pdf &); sleep 2; exit Variation on this would be nohup gnome-open *.pdf && sleep 2 && exit


8

Run mv .... filename to rename it back. (mv ..\.. filename would work too, but the \ is superfluous--as it was in your original command.) The file hasn't been deleted, which is why searching for recoverable deleted files didn't find it. Like in Windows, . and .. entries are present in every directory and refer to the "current" and "parent" directories ...


3

it is still in the same directory, just a 'hidden' file now. You can recover it by "mv .... filename".


38

It has gone nowhere, its in the current directory. It has been renamed as .... (four dots). As any filename having a . in front is treated a hidden file, so it has become hidden. So, if you do ls, you won't find it. Like always, you need the -a option of ls to view the hidden files i.e. ls -a to see it. Let me break it down, you ran mv filename ..\.. , the ...


0

Go to your system settings -> keyboard -> keyboard shortcuts and add a custom shortcut. For the command place the full path to the script. Now you can run it without terminal


5

Your understanding is basically correct. Both disown and nohup are used to allow you to exit a running shell session without stopping running jobs. Some clarifications: There's no reason to run nohup command & disown, nohup will already disown it for you. nohup is defined by POSIX while disown is not. This means that while many shells (e.g. bash, zsh, ...


4

A good idea is to check his scripts with this tool. Here is an annotated version of your error: 1 #!/bin/bash 2 sed -rne '/21:25:07/,/21:50:07/ p' server.log.2015-04-21 > /tmp/filename.log ; 3 du -sh /tmp/filename.log ; 4 if [`du -sh /tmp/filename.log` -gt 0] then gzip /tmp/filename.log ; ^––SC1009 The mentioned parser error ...


-2

if [ `du -sh /tmp/filename.log` -gt 0 ]; then gzip /tmp/filename.log; fi The spaces in if condition and fi at the end to close the if


6

You missed couple of points, the correct (Only syntatically) form would be: if [ `du -sh /tmp/filename.log` -gt 0 ]; then gzip /tmp/filename.log; fi There must be space after test ([) and before ] You need to put a ; (synonymous to newline) after first if condition You need to close the if condition using fi at last portion Also you should use $() ...



Top 50 recent answers are included