Tag Info

New answers tagged

-2

In the else if statement, you need to write it like this: elfi [con]; then echo "statement"


2

One option is to have it run as a bash script, just like your local environment that you are comparing to For the script to run under under bash, put this as the FIRST line of the program: #!/usr/bin/env bash


1

The problem is that you are using == as the equality operator (which bash supports) but then running the script under sh which doesn't support it. The solution is to replace: if [ $? == 0 ] ; then echo "A"; else echo "B"; fi With: if [ $? = 0 ] ; then echo "A"; else echo "B"; fi This will work under both bash and plain sh. While it may make no ...


-1

I did a simple echo before ssh-keygen. So su - <user> -c "echo |ssh-keygen -t rsa" This was tested on Redhat 6


6

The file in /proc/<pid>/io represent what you need. It's a bit scripting work to get an output similar to iotop. See the linux kernel documentation to the /proc/<pid>/io file values: rchar I/O counter: chars read The number of bytes which this task has caused to be read from storage. This is simply the sum of bytes which this process ...


1

You might want to take a look at fping and it's -t option: -t n Initial target timeout in milliseconds (default 500). In the default mode, this is the amount of time that fping waits for a response to its first request. Successive timeouts are multiplied by the backoff factor. By using fping you can just check the exit status ...


1

line ping -c 1 $ip 1> /dev/null discard result, so you can't know if you pings are over 500 ms. use ping -c 1 $ip 1> /tmp/ping.txt to keep ping's response, then in the part where ping is sucessfull awk -F/ 'NF>5 { if ( $5 > 500 ) exit 1 ; else exit 0 }' /tmp/ping.txt will give 0 under 500 ms and 1 if average ping is over 500 ms. ...


1

It would be more efficient to rewrite this, thereby avoiding the issue in the first place: #!/bin/ksh get_file_totals() { if [ -e "$file_name" ] then cut -c4-7 "$file_name" else echo "error" # consider stderr by appending >&2 fi } file_name="$1" get_file_totals


3

You're invoking ksh. The kind of substitution you are wanting to do works only since ksh '93. Is there a chance you are using an older version? Run ksh and check for the existence of KSH_VERSION. If it doesn't exist or is before '93, it's too old.


1

You can use some bandwidth monitoring tool, such as vnstat, for this. To install it on Linux Mint, do: sudo apt-get install vnstat Then, you can monitor the average speed of your connection over some specified time, and if the speed comes out to be lower than some specific limit, then turn off your WLAN. So, let's say you want to switch off your WLAN if ...


-1

The correct syntax is if ! $bool; then [statements]; fi. Example: bool=false if ! $bool; then echo "This is correct!" fi if [ ! $bool ]; then echo "This is wrong!" fi Output: This is correct!


0

You have two options here You can create a file with all the servers' IP addresses, then do the below while read -r ip;do ssh-copy-id -i .ssh/id_rsa.pub $ip done < servers.txt Assuming servers.txt is the file with IPs/hostnames You can put all your IPs/hostnames in a loop, and run ssh-copy-id like below for i in hostname1 hostname2 do ...


0

I had found the way to implement the automatic guest installation of default archiso image, controlling only host machine, however it's somewhat cumbersome. You need to combine VBox native functionality with exposed serial port over ssh. Enable virtual serial port support for VBox: VBoxManage modifyvm "$VNM" --uart1 0x3F8 4 --uartmode1 server "$SERIAL" ...


4

Using Ansible is fairly simple. Just replace <USER> with the real login name $ cd /path/to/public/key $ cat<<END > hosts host1.example.com 10.10.10.10 END $ ansible -i hosts all --ask-pass -u <USER> -m authorized_key -a "user=<USER> key='$(cat id_rsa.pub)'"


5

ClusterSSH gives you a window on each machine and with a common window to control all windows. If we are talking 10 machines this will work. If we are talking 100 machines, there will be to many windows. The beauty of ClusterSSH is that if one machine is not 100% like the rest, you can just click the window, and send keystrokes only to that machine before ...


6

Alternative using xargs, sshpass and ssh-copy-id: Assuming your credentials living in credentials.txt in format user:password@server: $ cat credentials.txt root:insecure@192.168.0.1 foo:insecure@192.168.0.2 bar:realsecure@192.168.0.3 You could do: tr ':@' '\n' < credentials.txt \ | xargs -L3 sh -c 'sshpass -p $1 ssh-copy-id $0@$2' Note: ...


23

Rather than type your password multiple times you can make use of pssh and its -A switch to prompt for it once, and then feed the password to all the servers in a list. NOTE: Using this method doesn't allow you to use ssh-copy-id, however, so you'll need to roll your own method for appending your SSH pub key file to your remote account's ...


1

You can add the line to the /etc/enviroment file like this: PATH=$PATH:~/root/scripts or Edit your ~/.bashrc and add your line here like this: export PATH=$PATH:~/root/scripts


0

Edit your ~/.bashrc file and add your export PATH line to it.


0

I recommend using phantomJS (or casperJS, which sits on top of phantomJS) for doing such tasks. console.log() is used to log to stdout. You could even do screen captures.


0

Just for the record, there technically is a way to convert JavaScript to HTML. I use inspect element in Chrome and FireFox a lot, which is the first place I learned HTML. If you paste a JavaScript in inspect element, it won't recognize it's function. I found a way around it. I taught myself everything I know which is what made it easier to figure this out. ...


1

00 09 * * * /home/flexsys/test.sh #!/bin/tcsh cd /home/A/B/C/ @ a = 0 while ( $a != 12 ) sleep 5 touch ABC.txt @ a = $a + 1 end This will run your script only once, but it will touch your file 12 times with a 5 seconds pause between each touch. As long as 12*5 is 60, you'll have ...


1

You can combine all the actions in one command: sftp user@host:/path/to/file/$(tail -1 file1.txt |tr -s ' ' |cut -d ' ' -f 9) This will fetch the file into the current working directory. If you need to fetch the file into another directory specify the destination directory as a next argument to the sftp command.


3

00-01 09 * * * /home/flexsys/test.sh (the job will start at 9:00 and run upto 9:01) That is not what this means. This means the job will run at 9am and run again at 9:01. Cron has no concept of killing jobs, only starting them. As for the while, you need to run the date command, find the number of minutes, and test if it is or isn't 00. On my system ...


1

Use grep with PCRE: $ var='/home/path/archive/logs/path.log-2015-04-13.0.gz:2015-05-13 00:43:49,779 INFO [DEUX-DR-SAMPLE-1] c.i.s.p.DeuxProxyPMMProcessor [DEUX : 361] SVRREQ|dataID|server request: (deliver: (pdu: 0 5 0 282190) (addr: 1 1 adress) (addr: 1 1 mssidn) (sm: enc: ASCII msg: id:dataID stat:pattern)' $ grep -Po '.*?SVRREQ\|\K[^|]+(?=\|)' ...


1

dos2unix: sed -i -r -e 's/\r$//' file unix2dos: sed -i -r -e 's/$/\r/' file


2

Windows line endings consist of the two-character sequence CR, LF. CR is the carriage return character, sometimes represented as \r, \015, ^M, etc. A Unix line ending is just the LF character. A way to convert Windows line endings to Unix line endings using only standard utilities present on all Unix variants is to use the tr utility. tr -d '\r' ...


0


-1

You can see this,I use service wrapper solved my problem at: here


2

And now, the systemd answer. You're using Ubuntu version 15. You have systemd. /etc/rc.local is at best a backwards compatibility mechanism in systemd. And as shown by the mess in the AskUbuntu question hyperlinked below, using it can go horribly wrong. So make a proper systemd service unit. You are creating a local, non-system non-package, service ...


2

You can simply add a line to call the script in /etc/rc.local. This file is the last of the init scripts to be run. Just make sure that /etc/rc.local is executable and owned by root.


0

You can use gksudo:- NAME gksu - GTK+ frontend for su and sudo DESCRIPTION gksu is a frontend to su and gksudo is a frontend to sudo. Their primary purpose is to run graphical commands that need root without the need to run an X terminal emulator and using su directly. Open Startup Applications (System Settings > ...


0

This is yet another way to assign a variable, good to use with some text editors that are unable to correctly highlight every intricate code you create. read -r -d '' str < <(cat somefile.txt) echo "${#str}" echo "$str"


0

grep (i.e., /bin/grep) will read from standard input if it is invoked with no filename arguments.  So it is simple to write a script that runs grep with input from standard input — just invoke grep with no filename arguments.  But grep must be given (at least) one PATTERN argument (or equivalent).  An extremely inflexible way to do that, which is unlikely to ...


0

Change your script to use gawk instead o awk. Simple test: # pkg list|awk '{system("pkg verify $1")}' # # pkg list|gawk '{system("pkg verify $1")}' PACKAGE STATUS pkg://solaris/driver/storage/ssd ERROR


1

An alias will work. I have grep aliased to grep --color=auto: % which grep grep: aliased to grep --color=auto And piping to grep has the behavior you desire:


4

If your concern is about aliases, just do: [[ $(unalias -- "$cmd"; type -- "$cmd") = *builtin ]] ($(...) create a subshell environment, so unalias is only in effect there). If you're also concerned about functions, also run command unset -f -- "$cmd" before type.


0

I fear you maybe wasted your time implementing that; ksh93 supports the builtin command. E.g. with ksh version 93t 2008-11-04: $ builtin ...creates list of all builtins $ builtin jobs umask ...returns with exit code 0 $ builtin jobs time umask ...returns with exit code 1 and prints "builtin: time: not found" Note also that the builtin command is a ...


1

Shell script extensions are quite useful. For example I often write scripts that have multiple files in multiple languages (eg. bash, awk and lua) in the same directory. If I need to search for a string in only the bash files, the extension makes this very handy, to reduce false positives. Or if I want to do a line count of all my bash code for that project. ...


2

It's correct in principle but you might consider reducing it to a single parted call. parted --script /device \ mklabel gpt \ mkpart primary 1MiB 100MiB \ mkpart primary 100MiB 200MiB \ ... Your alignment issue is probably because you use MB instead of MiB. You should not need an actual align-check command when creating partitions on MiB ...


0

Give file with text, try using pr and process substitutions syntax as below: $ pr -mt <(grep -i "^[a-z]" file.txt) <(grep -i "^[0-9]" file.txt) AAAA 1234 BBBB 5678 CCCC 9012 DDDD 3456 EEEE 7890 You can adjust width by -w9 or remove spaces by sed "s/ //g".


0

Based on comments - you probably want to read the manpage for adduser. In particular : -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with ...


1

I take it that "rolls up" means that all newlines are removed and the output of each command is thus "rolled up" to a single line. If so, your grep ... | awk ... will work, but you don't need both commands ("never use two when one will suffice" is generally a good idea). In addition, your command line has a couple issues (like no input for grep but a ...


2

For filtering data from file is better to use grep. For example: grep <search string> <filename> With awk you can use something like: awk '/string/ {command}' <filename> To get IPs counted you can use uniq -c <filename> This will provide you uniq IPs with count


2

It depends on the content of the shell script and the used shell. A shell script might contain boilerplate code, called a shebang, like the following: #!/usr/bin/env bash The special sequence '#!' instructs the exec() kernel system call to use the program defined right after it as the interpreter. This means that you'll have to look into the file to see ...


3

The ./foobar.sh file is started by running it with whatever follows the #! in the first line. If this line reads #!/bin/sh -x then it would be identical to the sh -x foobar.sh case (assuming sh is resolved to /bin/sh from the PATH). Maybe it is not started by sh but bash? The -x flag prints debug info, i.e. every command before it is executed.


1

The first version, with an explicit call to sh will run your script with sh (displaying trace statements, as requested by -x). The second one, which does not specify an explicit interpreter, will respect the shebang line, if any, or default to the shell you are currently running. For example, if your script has a shebang line of #! /bin/bash, or your shell ...


0

I'm surprised nobody mentioned the obvious zsh solution here yet: for file (**/*.csv(ND.)) { do-something-with $file } ((D) to also include hidden files, (N) to avoid the error if there's no match, (.) to restrict to regular files.) bash4.3 and above now supports it partially as well: shopt -s globstar nullglob dotglob for file in **/*.csv; do [ -f ...


0

Take the perl way. Test with: perl -ne 's/^\s*[0-9]+c[0-9]+$//g; if ($_ !~ /^$/) {print }' file.txt Change the file file.txt with: perl -ne 's/^\s*[0-9]+c[0-9]+$//g; if ($_ !~ /^$/) {print }' -i file.txt


0

grep (and egrep or its modern equivalent grep -E) is your friend: man grep See the -v option. Here: grep -Exv '[[:blank:]]*[0-9]+c[0-9]+[[:blank:]]*' file would filter out lines consisting of c surrounded by decimal digits and optional blanks.



Top 50 recent answers are included