# Tag Info

3

The >-sign represents an I/O-Redirection. With >stat.txt you redirect the standard output (stdout) of the application to the file stat.txt. It is redirected, so you will not see any output in the shell. If you want the output in the current shell AND the file pipe the output into tee: your_command | tee stat.txt Or.. your_command | tee -a stat.txt ...

3

It's possible that the output is being sent to stderr which is not captured by the > operator which only captures stdout. Instead, if you are using the bash shell, try routing stderr to stdout and into a file using the &> operator. For example: unpackdcm -scr ${in} -targ${out} &>stat.txt To redirect only stderr, use this: unpackdcm ...

3

You could try any one of these commands from the Parent folder. If you need to find all the files, find . -print > list_of_files If you just need the directories and the sub-directories inside them as well, find . -type d > list_of_files If you just need directories for single level, find . -maxdepth 1 -type d > list_of_files Now, with ...

2

The script will continue if sudo fails, for instance if the user doesn't have appropriate permissions in /etc/sudoers. The command could also be inside an if block. Other parts of the script would be executed if the condition is not true.

1

Last can includes users logins from previous reboots. As such, the following will only print users since the last reboot: last | awk 'NR==1,$1=="reboot"{if ($1 ~ /cfs264/ ) { count+=1; }}END{ print count; }' The first part of the awk command specifies a range - start from the first row until the first column is 'reboot'.

4

The following example counts the times I am mentioned without needing the lastloggedin file: $last | awk '$1=="yeti" { ++count } END { print count }' 106 If you insist in using or are forced to use the lastloggedin file, you can do it this way: $last > lastloggedin$ awk '$1=="yeti" { ++count } END { print count }' lastloggedin 106 Use ... 3 To get you started you can use awk to search for lines in a file that contain a string like so:$ awk '/CFS264/ { .... }' lastloggedin The bits in the { .... } will be the commands required to tally up the number of lines with that string. To confirm that the above is working you could use a print $0 in there to simply print those lines that contain the ... 2 Try something like this: (example output from busybox on OpenWrt on one of my routers) root@ap8:~# xargs -0 printf '%s\n' </proc/991/cmdline /usr/sbin/uhttpd -f -h /www -r ap8 -x /cgi-bin -u /ubus -t 60 -T 30 -k 20 -A 1 -n 3 -N 100 -R -p 0.0.0.0:80 -p [::]:80 /proc/$PID/cmdline contains the arguments of process $PID like a C-ish strings one after ... 0 Method #1 - Using ps You could use ps -eaf | grep 1234. Example$ ps -eaf | grep 28865 saml 28865 9661 0 03:06 pts/2 00:00:00 bash -c sleep 10000; while [ 1 ];do echo hi;sleep 10;done saml 28866 28865 0 03:06 pts/2 00:00:00 sleep 10000 NOTE: Busybox's ps doesn't include the -eaf switches as shown above from a typical ps that's included ...

3

You could use the -o switch to specify your output format: $ps -eo args From the man page: Command with all its arguments as a string. Modifications to the arguments may be shown. [...] You may also use the -p switch to select a specific PID:$ ps -p [PID] -o args pidof may also be used to switch from process name to PID, hence allowing the use ...

0

I suppose you have to do this in pure Bash script, but translating John1024's algorithm to awk gives a considerable speed-up: awk 'BEGIN{k=0;for(i=10000;i<100000;i++){j=i;if(gsub(/[456]/,"",j)==2)k+=i};print k}' This runs in less than 1/20 of the time that the bash version takes; it's also a little faster than a Python version that uses Python's ...

0

Getting started Whenever I have a project like this I like to approach it in stages. The first thing I like to do is add an echo to the inside the loop and then run it, to make sure that the loop is giving me what I want. #! /bin/bash for (( CON1=10000; CON1<=99999; CON1++ )) ; do echo $CON1 done Now when I run it I'll use head -5 to just show the ... 2 Here is one way of counting how many 4, 5, or 6 appear in your number and having bash execute a statement based on whether the result is two or not:$ con1=1457 $a=${con1//[^456]/}; [ ${#a} -eq 2 ] && echo Yes Yes 3 In bash you can test as follows: [[ tty = "/dev/pts/1" ]] && echo Access Granted. Welcome. tty will generally output something like /dev/pts/1 or not a tty As you mentioned, apparently in csh you can do as follows: if ($tty == "pts/1") then echo Access Granted. Welcome. endif

1

If you have GNU Parallel you can do any of these: parallel mkdir :::: list.txt parallel -a list.txt mkdir cat list.txt | parallel mkdir All new computers have multiple cores, but most programs are serial in nature and will therefore not use the multiple cores. However, many tasks are extremely parallelizeable: Run the same program on many files Run the ...

-2

Another, using the bash options set internal variable, $-. From .bashrc, # If not running interactively, don't do anything case$- in *i*) ;; *) return;; esac

5

From man bash under CONDITIONAL EXPRESSIONS: -t fd True if file descriptor fd is open and refers to a terminal. Assuming fd 1 is standard out, if [ -t 1 ]; then should work for you. The Advanced Shell Scripting Guide claims that -t used this way will fail over ssh, and that the test (using stdin, not stdout) should therefore be: if [[ -t 0 || -p ...

0

Test for the existence of the PS1 environment variable: # If $PS1 is null, not being run from a shell if [ -z$PS1 ] Alternatively you can test for it being not null, i.e., run from the shell if [ -n $PS1 ] 4 This script will create a directory for each of the lines in list.txt. It can deal with spaces but not other weird characters (such as \r or\t and the like, but that shouldn't be an issue here): #!/usr/bin/env bash while IFS= read -r dir do mkdir -- "$dir" & done < list.txt The & sends the job to the background so the script will continue ...

1

This worked for me: xargs mkdir <list.txt This works because if you give multiple arguments to mkdir it will happily create all the directories it can create. xargs simply "flattens" your text file by replacing newlines with spaces, thereby invoking mkdir with a long list of arguments containing all your directory names at once instead of one at a ...

-2

This code worked very will for me: #!/bin/bash while read i; do echo "$i" wait mkdir "$i" done < lis.txt

2

In your example, your confusing shell scripting commands. You have to pay special attention to which scripting language you're using and then adhere to its commands' syntax. In your example you're using turbo C shell (tcsh) however you're then mixing in Bash/Bourne shell commands and syntaxes. You can use the following approach if you truly want tcsh. Say ...

0

You don't need a loop. You can do: mkdir sed 's/^/<name_id>/' <path to list.txt>/list.txt

1

The number of arguments is in the parameter $#. if [$# -ne 2 ]; then echo 1>&2 "Usage: $0 DIRECTORY1 DIRECTORY2" exit 3 fi If you want to enforce that the arguments are both directories (as opposed to other types of files), test them with -d. The utility diff compares two files. With the option -r, it compares directories recursively. diff ... 1 The following python program should do what you want, or something very close to it. In the desired_output.txt the 3rd line seems to be erroneous: Mem_id#-aa3 : time- file1.txt value = ccx3 / file2.txt value= dd3 the dd3 should probably becc3 Apart from that the output from the program matches except for whitespace, which seems a bit irregular in ... 4 Processing arguments Processing arguments that are passed via a script's command line is as simple as follows. Say we had this script:$ cat cmd.bash #!/bin/bash echo "arg1: $1" echo "arg2:$2" Now run with no arguments: $./cmd.bash arg1: arg2: With 1 argument:$ ./cmd.bash hi arg1: hi arg2: With 2 arguments: $./cmd.bash hi bye arg1: hi ... 4 The shebang line you've seen may work on some unix variants, but not on Linux. Linux's shebang lines are limited: you can only have one option. The whole string -d -m -S screenName /bin/bash is passed as a single option to screen, instead of being passed as different words. If you want to run a script inside screen and not mess around with multiple files or ... 3 According to the screen man pages: screen -d -m Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. -S sessionname Set the name of the new session to sessionname. So when I ran the command you provided: screen -dmS name ./script.sh Screen starts a window called name and ... 2 You could do something like this to start a process with the desired PID. while true; do bash -c '[[ "$$" == 99999 ]] && echo PID is 99999'; done You can wait until you get the desired PID and probably replace the echo statement to whatever you actually need to test. References will the same pid be used after getting killed? EDIT Why the ... 1 Whatever you are trying to do there is most probably the better approach, but if you are determined something like while [[ 1 == 1 ]]; do sleep 10000& done will start many sleeps, but it may take a while to start all of them. When you will have enough processes just hit Ctrl-C to exit while loop. 5 Your script is a sed script, not a shell script. So you don't need to put sed at the beginning of the line, or put quotes around the commands. Change it to: #!/bin/sed -f s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/192.100.100.100/g 1 This is a (far from elegant) partial solution to your problem. It uses the first column as id column (it does not have to be the first one but you must definitely have one) and introduces a third dimension suffix to store multiple occurences of the same key. In the end it tries to find those keys of file 2 which have not been found in file 1. BEGIN { ... 2 In some Linux distros that I have checked (e,g, Ubuntu 14.04), the packaged cal comes from BSD and not GNU Coreutils. The BSD version does not seem to accept days as a parameter; only months and years. The Ubuntu version does have a -H YYYY-MM-DD option, but that doesn't seem to help. Instead I would use the date utility. Assuming the GNU Coreutils under ... 1 [[ is actually a command, and like other commands you need whitespace to separate its arguments: if [[$? -eq 0 ]]; then # ...^

1

There is a space between your dollar $and your month variable: cal$day $month$year 2> /dev/null It should be: cal $day$month $year 2> /dev/null 3 Well, this one is not exactly the way you want. But still it could be useful for the second option in your question. Install the required packages. sudo apt-get install msmtp-mta Edit the following file to add the details. If the file doesn't exist, you could create it. vi ~/.msmtprc #Gmail account defaults logfile ~/msmtp.log account gmail auth on ... 0 I think it is because of the "noexec" mount option for the folder your script is in. You may try to check that by this command mount | grep df -P /path/to/folder/with/script | tail -1 | cut -d ' ' -f 1 1 I found the following 2 questions within the U&L site that would seem to give hints as a possible way to do this. These 2 questions: View all user's printing jobs from the command line How to show the CUPS printer jobs history? Would seem to imply that you could use lpstat to get what you want. I noticed that I could run this command:$ sudo ...

4

You can use public key authentication: on the server, add a line with the command run by rsync (for security) and your public key to ~root/.ssh/authorized_keys. See the sshd(8) man page for information on the authorized_keys file format.

2

Add shebang, since you are using [[ most probably #!/bin/bash is what you want Try to stick with one test syntax (either single bracket [ or double [[) Instead of << (here document) most probably you want <<< (here string) At the end of the script while loop is not closed, expect done somewhere There is one too many fi. (instead of done???) ...

0

Extension or improvement of terdon's code based on the some logic in this answer #!/usr/bin/env perl ## This is the path to the target directories my $path="/Users/Masi/Dropbox/"; chdir$path or die "cannot chdir '$path'"; ## Iterate over the directories foreach my$dir ( "Cardiology", "Pathophysiology", "Patology and Biopsy", "Physiology", ...

12

Here is the processing: a[$0]: look at the value of key$0, in associative array a. If it does not exist, create it. a[$0]++: increment the value of a[$0], return the old value as value of expression. If a[$0] does not exist, return 0 and increment a[$0] to 1 (++ operator returns numeric value). !a[$0]++: negate the value of expression. If a[$0]++ return ...

12

Let's see, !a[$0]++ first a[$0] we look at the value of a[$0] (array a with whole input line ($0) as key). If it does not exist ( ! is negation in test will eval to true) !a[$0] we print the input line$0 (default action). Also, we add one ( ++ ) to a[$0], so next time !a[$0] will evaluate to false. Nice, find!! You should have a look at code ...

3

Assuming your shell is bash, this can be a one-liner: perl -i.bak -pe ' /\\begin\{verbatim\}/../\\end\{verbatim\}/ or s/->/\$\\to\$/g ' {Cardiology,Pathophysiology,"Patology and Biopsy",Physiology,Propedeutics,Radiology,Rheumatology,Surgery}/*.tex Note that {...} is a regex quantifier, so the braces need to be escaped. I'd write your code as: ...

2

Another approach: if >> /path/to/file then echo "writeable" else echo "write permission denied" fi This will attempt to open the file for appending, and, if that succeeds, run no command (i.e., run a null command) with output to the file.  Beware that this creates an empty file if it didn't exist. The -w operator of the test command might ...

13

Just use the -w flag of the test utillity: [ -w /path/to/file ] && echo "writeable" || echo "write permission denied" Note that if you're going to write to the file later, it's still possible that you won't be able to write to it. The file may have moved, the permissions may have changed, etc. It can also happen that -w detects write permissions ...

12

The easiest way to accomplish what you want, is to delete all files in the directory that are older than 30 days. You can use this find command: find /path/to/log/ -maxdepth 1 -name "NameLog.log*" -mtime +30 -delete Explanation: (see: explainshell) -maxdepth 1: don't go deeper into the folder structure -name "NameLog.log*": applies only on log file with ...

2

I was going to extend my original code but it is getting to a point where it's much easier to just reimplement everything in Perl directly: #!/usr/bin/env perl ## This is the path to the target directories my \$path="/Users/Masi/Dropbox/"; ## The target directories my @directories=("Cardiology","Rheumatology","Surgery"); ## Iterate over the directories ...

3

slm's answer here hasn't taken into account that you asked about the Korn shell, not about the Bourne Again shell. The (93) Korn shell has no built-in expr command, so when using expr in Korn shell scripts you are using an external expr command. This is not a problem per se. After all, it's how one did things with the Bourne shell, which also had no expr ...

1

You'll need to dissect this script a bit to see why it's failing. This isn't that hard a task, since you have the source code to it already. I'd start with confirming that the commands in the function implementation, get_video_duration_in_seconds_from_file() is correct. Specifically when I ran this command on a few .mp4 files I had, it would return nothing: ...

Top 50 recent answers are included