Tag Info

New answers tagged

1

If you are not writing your own software but want to start/stop existing service, than like @jasonwryan wrote, RHEL/Fedora are using systemd. The command for handling services is systemctl. systemctl start/stop/restart servicename If you want to list the installed services, use: systemctl list-units


0

Look at /etc/rc.d/init.d You'll have a few services there to examine. You can also test the service script by checking the status of your net work with: $ sudo service network status


1

Your first two commands are not doing anything. You are catting the two files and passing them to grep which is ignoring it since you have given it a file to search in. You only needed grep -Ff text.txt vendor.xml | sort -u | uniq -c That doesn't work the way you expected because grep is smarter than that. When you give it a list of patterns to look for, ...


3

Here's an awk answer: awk 'NR==FNR {count[$0]++; next} $1 in count {print count[$1],$0}' text.txt vendor.xml | sort -nr


6

join combines the files (needing sorted inputs): $ join <(sort text.txt) <(sort vendor.xml) 00:10:f6 vendor="micro" 00:10:f6 vendor="micro" 03:48:03 vendor="apple" 8f:91:34 vendor="dell" 93:ab:c6 vendor="sun" So all what's left is to add uniq -c to do the counting: $ join <(sort text.txt) <(sort vendor.xml) | uniq -c 2 00:10:f6 ...


0

Usually, the capabilities are inherited to the children. As stated in the manpage : A child created via fork(2) inherits copies of its parent's capability sets. The issue with the scripts is they are not executables. Your calling program (usually the shell) has to check the first line for a shebang, then call the real interpreter (set in the shebang) ...


1

You were close, just unnecessarily complicated this task. Try awk -f script.awk main.txt index.txt (notice reverse order of files) with the following script: #!/bin/awk BEGIN { FS = "|" } ( NR == FNR ) { lookup[toupper($1)] = $0 } ( NR > FNR ) { key = toupper($1) n=split(lookup[key], replacements, "|") replacements[$2+1]=$3 for ...


1

My script works, if both your values separated by the delimiter have the same amount of characters. I hope it'll help a little. EDIT: I've rewritten the code, so it takes an arbitrary number of lines. But now I see, you've added information, that more than one delimiter is possible :-) I'll look at it later. If you wanted arbitrary number of spaces, it ...


0

You can perform substitutions in the previous command. This won't work with your {a, b} example, because all instances of 'a' will be replaced with a 'b'. But imagine you want to execute the following commands: run-command --a --whole --lot --of --parameter --format xml run-command --a --whole --lot --of --parameter --format son You can do it with ...


0

If the application is being executed locally you can set the environment variable $DISPLAY like so in a terminal: $ export DISPLAY=:0.0 Afterwards you can then invoke MNI in the same terminal: $ ...MNI command...


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


2

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

An alternative to the methods provided by @Renan and @jimmij yields wireshark-filter the big winner on my system. for i in {1..9}; do du -sh man"$i"/*.gz | grep -v "^..0K" | grep -v "^0\|^12K\|^16K\|^[0-9][0-9]K" ; done Based on that I did a opened each of the largest entries with man and checked the number of lines at the end of the file with a :f and ...


9

You can calculate it yourself for your system with simple command $ find /usr/share/man/ -type f -exec ls -S {} + 2>/dev/null | head | while \ read -r file; do printf "%-40s" "$file"; \ man "$file" 2>/dev/null | wc -lwm; done | sort -nrk 4 which returns on my box (file) (lines) (words) (chars) ...


3

Man pages are stored in /usr/share/man/manX where X is the section (described in man man). They're compressed in gzip format, so let's assume a larger compressed file means a bigger manpage. By checking in /usr/share/man/man1 (section 1: Executable programs or shell commands) with the command gzip -l *.gz | sort -n -k2, I get this (which will probably vary ...


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`



Top 50 recent answers are included