Tag Info

New answers tagged

0

Another option for simple web pages is 'lynx' which has a -dump option. It will save to a file a 'readable' view of the web pages content. lynx is a bit old and hairy now, and doesn't support either javascript nor frames. But if your trying to strip out 'human readable' content from a flat low/non-interactive web page, it a bit simpler to work with than ...


1

As one who has worked in a multitude of ?nix environments, I have had to write in a wide variety of shells. Believe it or not, across platforms, the shells are not the same. So if you maintain your personal library in multiple shells (when necessary) it is very helpful to use extensions to ID the shells. That way when you move to another platform and the ...


1

You need to quote the URL, otherwise the & signs will be interpreted as command delimiters. That said, you can either redirect the curl output to a file (curl [...] > index.html) or use wget, which saves to file by default.


1

The simplest way would be to use zsh's numeric range glob: mv PRC<257-1516> /else/where/ The range operator matches numbers with or without leading zeroes, so PRC257, PRC0257, PRC00257, etc. are all included. You can leave the end of the range blank, e.g. PRC<257-> to move all files from 257 onwards. It doesn't matter how many files in the ...


0

An application that has handled a KeyPress event is not generally expected to handle the subsequent KeyRelease event. If the user presses a key, then switches to another application, and then releases the key, then the focus change is expected to happen when requested, it is not supposed to be delayed until the user has released the key. X11's architecture ...


1

Implementing @Izkata's suggestion using inotifywait with paced event response to keep the rsyncs down to at most 1 every 5 minutes while still responding quickly to initial changes: #!/bin/sh # usage: whateveryouwanttotcallthis "$directorytowatch" rsync args here cd "$1" || { echo "${0##*/}: can't cd to $1"; exit 1; } shift rsync -nq "$@" || { echo "rsync ...


0

find -name '*.jpg' -print0 folder | grep -zZ -vf name.log | xargs -0 COMMAND replace COMMAND by ls -l and if you like it by rm


3

The awk solution to round up the list of alternatives: awk -v RS=', ' -F'=' '$1=="Foo"' <file> Treat each record to be delimited by ', ', and split each record into fields on the = character (using -F) as well. Then it's just a matter of matching on the first field $1. The suggestion shown here is a simple string matching, feel free to use regexes, ...


1

Select range in braces: cp PRC{0257..1516} destination/


1

If you don't have a grep available with the -o option, this ought to do the trick as well: sed -e 's/, /\n/g' | grep '^Foo=' That's using sed to replace every comma+space with a newline (breaking each key-value pair onto its own line), and then grep to search for only the 'Foo' key. Test case: printf "%s\n" "Foo=1, Bar=2, Baz=3" "Bar=4, Foo=2, Baz=3" ...


1

Given your example, a brittle solution could involve cut: tr ', ' '[\n*]' <input | cut -sd F -f1- ...which would put each key/value pair on a separate line by transforming the intervening commas and spaces into \newlines, and then cutting out lines which don't contain an F. But that is a highly specialized example, and can only work if you can be sure ...


1

Depending on the complexity of your real-world situation, this sed command may be sufficient: sed -n 's/^.*\(\<Foo=[^,]*\).*/\1/p' Here's the worked example FIELD='Foo' sed -n "s/^.*\(\<${FIELD}=[^,]*\).*/\1/p' << xxEOFxx Foo=1, Bar=2, Baz=3 Bar=4, Foo=2, Baz=3 Bar=42, Baz=42, Foo=3 xxEOFxx Foo=1 Foo=2 Foo=3


5

grep can do this with -o option: grep -o 'Foo=[^,]*' file


2

You could use what DevNull suggested which rsyncs periodically. Personally I would use inotify. It is a nifty tool that you can give a folder to watch. It sets up watches and notifies you whenever a filesystem change occurs. You could then trigger an rsync based on the trigger from inotify. For the specific case at the end you talk about, you can use the ...


4

Per your bonus question, add the following line below the rsync command in the shell script I provided below. I wrote this in the comment but I'll officially add it to my answer here: find /auto/std2/nat2/B -name '*.zip' -exec sh -c 'unzip -d `dirname {}` {}' ';' This will handle unzipping all the zip files that are copied via rsync from folder ...


1

Update (from our chat), I think a case statement works better for what you are trying to accomplish here: #!/bin/bash clear lred='\033[1;31m' red='\033[0;31m' NC='\033[0m' # No Color blue='\033[0;34m' lblue='\033[1;34m' # tells echo to enable backslash escapes echo -e "${red}Welcome to Lab 7 Utilities Menu ${NC}" sleep 3 clear echo -e "${lblue}Choose one ...


0

This is really easy w/ pax. It has a notion of a -substitution option which can change filenames as they are written. You can specify more than one -substitution argument as well. And, most relevant here, is that selected members only have as many -substitution arguments applied as are necessary to successfully make one match, but any substitution which ...


2

This is fairly easy in Python with os.walk. Warning, untested code. I assume that the list of names contains one name per line with #!/usr/bin/python2 import os names_file = open('names.log') names = set(line.rstrip('\n') for line in names_file.readlines()) names_file.close() for root, dirs, files in os.walk('/path/to/top/directory'): for name in ...


-1

If you will satisfy with bash I'd like to offer following algorithm (it could be realized on any scripting lanuage): Build list of present files: find /path_to_folder -name "*.jpg" -fprint files.tmp Sortfiles.tmp and name.log than compare its by comm -23 files.tmp name.log Pass the list of files unique for files.tmp to rm command Be aware with path of ...


0

Which distribution are you using, and which shell? I suppose you are talking about graphical environment. You might have success with using source directive in .bashrc, .bash_profile or .profile, or simply running the script in these by addressing it.


7

The usual way of handling switches and arguments is with the getopts function. In bash this is a builtin and you can find information about it in the bash man page (man bash). Essentially, you declare a string that tells getopts what parameters to expect, and whether they should have an argument. It's getopts that handles bunched parameters (eg -abc being ...


1

You don't have to use any Bash-specific features to do this: #!/bin/sh while true do case "$1" in -a) echo Saw -a! ;; -b) echo Saw -b! ;; -c) echo Saw -c! ;; -?) cat <<USAGE usage: $0 [-a] [-b] [-c] args You cannot currently combine options, as with -ac. USAGE exit 1 ;; *) ...


5

The python script at the end of this answer doesn't do exactly what you want but should come close. I added the 10999 directory to show how directories at the same level are displayed. This code doesn't handle subdirectories in the zip file nicely, for that you would best write a zip_recurse routine that can call itself recursively. The code has been tested ...


0

The special parameters "$*" and "$@" refer to every argument in the shell's argument array each in different ways. "$@" - this parameter is how you refer to the shell array as a list of strings. With this you can expand a faithful reproduction of the argument array for handing off to another command. The expansion of "$@" can also be added to at either ...


1

From man bash: Special Parameters The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. * Expands to the positional parameters, starting from one. When the expansion is not within double quotes, each positional parameter expands to a separate word. ...


0

Special Parameters $* and $@: There are special parameters that allow accessing all of the command-line arguments at once. $* and $@ both will act the same unless they are enclosed in double quotes, "". Both the parameter specifies all command-line arguments but the "$*" special parameter takes the entire list as one argument with spaces between and the ...


1

Amongst other things: "$*" expands to "arg1 arg2 arg3 …" "$@" expands to "arg1" "arg2" "arg3" … Thus "$@" is safer. $* may be older, existing for backwards compatibility.


0

This is all about how arguments separators (by default spaces) are handled: "$@" will expand to a sequence of strings, while "$*" will expand to a single string. Take the example script "test.sh" below: #$/bin/sh for i in "$*"; do echo $i done echo "====" for i in "$@"; do echo $i done When called with 4 args invoked like this: ./test.sh 1 2 3 "4 ...


3

The simple primitive explanation is: $* all set arguments is one string (arguments are separated by the first character in $IFS) $@ each argument is different string (arguments are separated by newline) From man bash: * Expands to the positional parameters, starting from one. When the expansion is not within dou‐ ble quotes, each positional ...


1

The difference lies in the way the two variables are expanded. $@ expands so that each argument is separated by a \0NUL and seen individually. Thus, given foo arg1 arg2 arg3, $@ will become arg1\0arg2\0arg3. In particular, each argument is protected from splitting, so that, if arg1 were foo bar, unless further processing is done, it will be seen as foo bar ...


0

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- sadiq khatri --> <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-6007294001515858" data-ad-slot="2073708321"></ins> <script> (adsbygoogle = window.adsbygoogle || ...


5

The "while" command isn't looking for a boolean value, it's looking for a return code of "0" which indicates successful execution of the command. So in the case the while command, a command that returns 0 is "true" and anything else is "false". Even when you're doing a comparison, Bash treats that like a command which is returning a successful error code ...


7

When dealing with return codes "0" is a success and non-zero is failure. The syntax of a while loop is: while COMMANDS; do ...; done The while statement checks the return code of the last command in the provided list of commands. In you last example of while 0, this will attempt to execute a command called "0" and check it's return code. A literal 0 is ...


5

The shell does not expanded condition like you think. In shell, an error code 0 indicated that the command has completed successfully. Any non-zero error code indicated that there was error. For more concisely, POSIX define while loop as: The while loop shall continuously execute one compound-list as long as another compound-list has a zero exit ...


2

The exit code is not a boolean value, is an integer, by convention the zero value is success, so you are thinking in negative logic from Bash's point of view


0

!/bin/bash tar -czvf /var/local/backup.tar.gz -C /home/administrator/ Try this it should solve your problem. You can use -P switch as well.


1

Change it to: #!/bin/bash tar -czvf /var/local/backup.tar.gz /home/administrator Now it will be created in /var/local directory.


0

To execute vim in non-interactive mode, you can use either +{command}/-c {command} or -s parameter which will allow you to execute the vim commands after the first file has been read. Check few examples below. Simple standard input and output using pipes can be achieved by the command: $ echo Example | vim -es '+:wq! /dev/stdout' /dev/stdin | cat To ...


1

Check the Filesystem hierarchy standard to see what standard locations exist on a Linux system. If you need to guarantee that the file is preserved between executions, then indeed /tmp is not the right place. /tmp is often wiped on a reboot, and it's common to have a cron job that deleted old unopened files from /tmp as well. /var/tmp is not normally ...


4

Then use expect: expect -c 'spawn ssh serversuser@server' \ -c 'expect "serverprompt" {send /path/to/your/script\n}' \ -c 'expect "Enter application password to run the script:" {send yourpassword\n}'


0

Ok it looks like the EOF was just a lot more sensitive than I excpected this doesn't work vim -E -s dummy.out <<-EOF :%s/old/new/g :%s/old2/new2/g :%s/old3/new3/g :update :quit EOF this does vim -E -s dummy.out << EOF :%s/old/new/g :%s/old2/new2/g :%s/old3/new3/g :update :quit EOF


2

You have to use : if [ `ls -l ~/sysbackups | wc -l` -gt 5 ];then echo XXXXX fi;


0

This makes the same assumption about spaces as @Gilles answer does, but it eschews the while...read loop. It first backslash escapes any occurrence of any of sed's BRE metacharacters, then prints its current line number, then globally substitutes every pair of not-space characters it can find into a working sed substitution statement. Next in the pipeline a ...


2

Alternatives Unless you really need special Vim capabilities, you're probably better off using non-interactive tools like sed, awk, or Perl / Python / Ruby / your favorite scripting language here. That said, you can use Vim non-interactively: Silent Batch Mode For very simple text processing (i.e. using Vim like an enhanced 'sed' or 'awk', maybe just ...


0

I was trying something very similar with ssh and passing a command line through it. e.g. ssh <somehost> ls -l "$PATH" I found that simply defining "$PATH" didn't do the trick - it still threw up errors. However if I ran ssh <somehost> ls -l "\"$PATH"\" This worked. The trick is to ensure an additional set of " " gets passed to the ssh ...


1

automatic edition should be done using sed(1) (see man sed ) The commend your are looking for are sed -i -e s/old/new/g -e /deletethis/d -e '/^$/d' postgresdb.out I am not sure what you expect with :%s/\n\n//d. where -i means edit in place (usually sed will output edition do standard output) -e ... do the edition/deletion -e '/^$/d' shoudl delete ...


0

Assuming you already have one user that auto-logs in, you can probably use a script that runs after logging in (use gnome-session-properties) that: gets a list of users to auto-login from some file checks for each of those users if they are logged in yet if one is not, use xdotool to switch to the first user (by simulating clicking on Menu and then ...


0

from subprocess import call import random while True: param = random.randint(1,100) #add random first or from random import randint runmyscript ="tmux send-keys -t mysession %s 'python myscript.py param' "%str(parma) call(runmyscript,shell=True)#you should add if or something to break loop


2

08 starts with a 0 thus is regarded as octal in some contexts (with digits between 0 and 7, hence the error beginning at 08). The solution: filter out the 0; if you need to output a leading 0, there's printf %02d.


0

You can start with for port in $(cat demo); do mypid=$(netstat xxxx | grep ":${port} " | grep LISTEN | sed -e 's/.*LISTEN//'| cut -d/ -f1) ps -fp ${mypid} done Possiple changes (what you are familiar with): Use xargs for calling ps ... -f1) | xargs ps -fp Use sed for cutting the / Use while loop cat demo | while read port; do



Top 50 recent answers are included