w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Shell script translate single into multiple lines based on a parameter
The simplest is to replace the end of the line (not the , but the end of the line) with <br>, like so: (echo line one; echo line two) | sed -e 's/$/<br>/' or in your case: sed -e 's/$/<br>/' < inputfile Replacing the tabs at the beginning of the line is done similarly using the caret as the beginning-of-the-line marker. As a complete script: TAB="$(echo -e " ")" sed -e "s/^$TAB$TAB$TAB$TAB(.*)/<div style="margin-left: 160px;">1</div>/ -e "s/^$TAB$TAB$TAB(.*)/<div style="margin-left: 120px;">1</div>/ -e "s/^$TAB$TAB(.*)/<div style="margin-left: 80px;">1</div>/ -e "s/^$TAB(.*)/<div style="margin-left: 40px;">1</div>/ -e 's/$/<br>/' < inputfile > outputfile Note 1: The at the en

Categories : Linux

Shell script - Multiple user appending the same file at the same time
You could make use of a message queueing system: POSIX message queues: http://www.linuxhowtos.org/manpages/7/mq_overview.htm Beanstalkd: http://kr.github.io/beanstalkd/ POSIX Message Queue for Ruby: http://rubygems.org/gems/posix_mq Perl: http://search.cpan.org/~iljatabac/POSIX-RT-MQ-0.03/MQ.pm Python IPC: http://semanchuk.com/philip/posix_ipc/ Other threads: Are message queues obsolete in linux? http://unix.stackexchange.com/questions/70837/linux-command-to-check-posix-message-queue What is the best free tool for managing MSMQ queues and messages? The idea is to create a server process that would receive messages and store on a buffer. It would only print a line on the logfile everytime a message from a process already has a complete line.

Categories : Shell

Running two node servers from a single shell command using a shell script
Your command does not work because you are trying to have two processes running in the same shell. Instead, you should 'spawn' the node processes into different processes. Try this command: node project/rest.js & node static-server.js &

Categories : Node Js

how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

unable to access variable declared in ksh script to csh script using shell script
The ksh script is not doing what you think it is doing when used by ksh; it sets $1 first to MyUser=root and then MyPassword=shroot. However, when you source it from your C shell script, because the syntax is compatible with C shell (checked with tcsh), you would set the two variables. If you sourced the script from a Bourne-shell derivative, the exit at the end of the ksh script would cause the shell to exit; it does not seem to cause the C shell to exit. So, what you've got is a weird hybrid. Normally, you stick to one language and use it exclusively. Where you need to use another shell, you can do so, but you simply run the script written for the other shell. You can communicate to the other script with environment variables. You don't normally try writing sourceable code that ca

Categories : Shell

sentence as user input - multiple times from terminal - bash script
This is because in your second call to read, you are using the -a argument which does: The words are assigned to sequential indices of the array variable aname, starting at 0. aname is unset before any new values are assigned. Other name arguments are ignored. That appears to be not what you want.

Categories : Bash

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

run shell script in program and input parameters
I didn't remember exactly what the command was called, but it exists! Now, I have found it. The expect command will wait for a prompt like the one you have described, and then it will pretend to be a keyboard and it will enter data. A quick example: #!/usr/bin/expect set timeout 20 spawn "./parse" FOLDER="/x/y/z" LOGIN="Randy" PASSWORD="horse_stapler" PROJECTID="136729" expect "parse new " { send "$FOLDER" } expect "Login>" { send "$LOGIN" } expect "Pw>" { send "$PASSWORD" } expect "projectID>" { send "$PROJECTID" } interact ... more examples like this one here. BUT WAIT. There are 2 things that you need to know. Firstly, The reason that the top of the script is "#!/usr/bin/expect" is because this is not bash. Instead this is it's own special kind of script. Read mor

Categories : Shell

Executing shell script that takes a input through ant
You may want to pass the $Orgname in the build.xml. <project name="Sample" default="automate"> <target name="automate"> <exec executable="/bin/bash"> <arg value="echo 'yak' | /root/test/Work/input.sh"/> </exec> </target> </project>

Categories : Unix

How to parse 2 input CSV files using shell script
Not sure what you want to do with the variables, but you can join the two files and then read it in a loop as shown below: join -t, -1 2 -2 1 <(sort -t, -k2 file1.csv) <(sort file2.csv) | while IFS=, read -r -a arr do var1=${arr[0]} var2=${arr[5]} echo "$var1 $var2" done You can also use awk to print out fields: join -t, -1 2 -2 1 <(sort -t, -k2 file1.csv) <(sort file2.csv) | awk -F, '{print $1,$5}'

Categories : Shell

Using a file input as stdin for a shell script does not work
What do you need the <&1 for? Remove it, and it works. while read CMD; do ./test.sh < input.txt BEGIN get_start END get_stop END get_uknown_command END

Categories : Linux

How can I break out of a shell script loop if the input is being handled by an inner "while read"?
#!/bin/bash mkfifo outputs for val in {1..10}; do echo "$RANDOM/20000" | bc | xargs sleep echo $val done > outputs & group=0 time=$(date +%s%N) while read line; do ctime=$(date +%s%N) [ $(( $ctime - $time )) -gt 1000000000 ] && let group++ echo "read time=$group read=$line" time=$ctime done < outputs

Categories : Bash

Check input consists only of numeric characters in shell script
Try using start/end anchors with your pattern. If you don't, the match succeeds with a part of a test string. Don't forget that you have to use a pattern matching the complete test string if you follow this suggestion. if [[ $1 =~ ^[0-9]+$ ]]; then echo "Invalid input" fi Check out this SO post for more details.

Categories : Shell

Shell Script that performs different functions based on input from file
Use read to input the lines. Do a case statement on their prefix: { while read DATA; do case "$DATA" in #*) ... switch function ...;; *) eval "$FUNCTION";; esac done } <inputfile Dependent on your problem you might want to experiment with setting $IFS before reading and read multiple variables in 1 go.

Categories : Linux

Using the output of a 'grep search' as the input of a 'yum update' (Shell Script)
You have two options of how to call a command (yum in your case) with output of another command (grep in your case): one is to do something like: $ yum update $(find-repos-of-install | grep rpmfusion) Another one is to use xargs, something like: $ find-repos-of-install | grep rpmfusion | xargs yum update

Categories : Shell

The DB2 SQL script is hanging in shell script, but working successfully in command line
Are you sure DB2 is blocking? Did you put a semicolon between commands db2 CONNECT TO ktest4 ; db2 -v -f /tmp/sql/application_system/opmdb2_privilege_remove.sql.5342 In order to trace the execution, I advise you to put some output, in order to detect where is it blocking date ; db2 -r /tmp/output.log CONNECT TO ktest4 ; db2 -r /tmp/output.log values current timestamp ; db2 -r /tmp/output.log -v -f /tmp/sql/application_system ; db2 -r /tmp/output.log values current timestamp ; db2 -r /tmp/output.log terminate With a command like this, you will save all outputs, and then you could check where is the error.

Categories : SQL

Source in shell script doesn't work when script called with arguments
With your script, you are automating the following commands, if xilinx ise is typed in from the command line: $ cd /home/sclukey/Xilinx $ source /opt/Xilinx/14.6/ISE_DS/settings32.sh $ ise The response from the script indicates that there's no ise program in the path. I would check to see where ise is, and if settings32.sh sets up a path for it.

Categories : Bash

bash shell script error works on command line, not in script
Variables are supposed to contain data, and bash treats them as data. This means that shell meta-characters like quotes are also treated as data. See this article for a complete discussion on the topic. The short answer is to use arrays instead: ASCIIDOC_OPTS=( --asciidoc-opts='-a lang=en -v -b docbook -d book' ) DBLATEX_OPTS=( --dblatex-opts='-V -T db2latex' ) cmd=(a2x -v -f pdf -L "${ASCIIDOC_OPTS[@]}" "${DBLATEX_OPTS[@]}" "$1".asciidoc) # Print command in pastable format: printf '%q ' "${cmd[@]}" printf ' ' # Execute it "${cmd[@]}" Make sure not to use eval: eval "$cmd" #noooo This will appear to work with your code as you posted it, but has caveats and security problems.

Categories : Bash

Multiple inputs in shell script
Those "EOF markers" are called heredocs. And you can use them if the program/script gets its input from stdin (most do). some_command << EOF do this do that EOF

Categories : Mysql

How to keep blank lines in the end of a file when I user cat command in shell script
You don't need cat command here, directly use awk like this: awk 'END {print NR}' a.txt Your problem is in storing the cat's output in a shell variable. Even this will give right output (though case of UUOC): cat a.txt | awk 'END {print NR}' Update: When you try to do this: a=`cat a.txt` OR else: a=$(cat a.txt) Pitfall is that the process substitution i.e. command inside reverse quote like you have or in $() strips trailing newlines. You can do this trick to get trailing newlines stored in a shell variable: a=`cat a.txt; echo ';'` a="${a%;}" Test the variable value: echo "$a" printf "%q" "$a" Then output will show newlines as well: jhasdfj sdfjalskdf $'jhasdfj sdfjalskdf '

Categories : Linux

email send works via perl script but not shell script
You have to export the smtp variable, otherwise mailx will not see it. Like this: #!/bin/sh SUBJECT="some subject" export smtp=10.233.1.199 EMAIL=abc@xyz.com echo "some message" | mailx -s "$SUBJECT" "$EMAIL" Btw the smtp variable is not mentioned in man mailx in my system nor in another Linux system I have access to. But I found it mentioned in an answer on superuser.com. That is to say, I'm not sure this would work on systems where it is not mentioned in man mailx, but if it works for you that's great.

Categories : Perl

Shell Script. Finish mysql dump before continuing script
In general, programs under *nix wait until completion before returning (though there are exceptions to this, mostly GUI applications). mysqldump follows this, therefore you do not have to do anything.

Categories : Mysql

Automator replacing character with apple script or shell script
Try: set myString to "This\is\my\string" -- really Thisismystring set {TID, text item delimiters} to {text item delimiters, "\"} set myString to text items of myString set text item delimiters to "/" set myString to myString as text set text item delimiters to TID return myString or set input to "This\is\my\string" -- really Thisismystring set output to do shell script "echo " & quoted form of input & " | sed 's/[\]/\//g'"

Categories : Shell

Combine shell script and data files into one runnable script?
Here you go: curl http://stacked-crooked.com/sh -d 'echo H4sIABq0uFEAA+3VvW6DMBSG4cy+ihOyJFICx4TYQ6rOvQ0CJBBRXPHTWqp67zVFyUgn6I++ZzlCWLI9vGD9fDE1ZlZRRP3USn9NDofnQbgnGcqDkntWShJLqZgXxJOfzOmaNq7dUa6X2oytc8vO55H3w03oPv+IVVElZZdm9NC0aWH8/FH89JFgRtZPJt/j2/5d87f+dch9/wct0f8c7v171s898RwX1XpD7+Kla5u195SVpdnSm6nLdOltjuIDX4f/pe6qyffou9d6pP9I3/qXUkd9/zqM0P8cVsvgVFTBKW5y0WQt7bJXK8QlSWhnyJL7PQg/sKgeAAAAAAAAAAAAAAAAAOC3+wQXspMdACgAAA== | base64 --decode | tar -xzv && ./run'

Categories : Bash

Triggering a windows batch script from unix shell script
Take a look at this: http://stackoverflow.com/a/16720186/2471910 It talks specifically about invoking a windows program from another windows machine (instead of a unix machine) but the concepts are the same since ssh is available on unix as well.

Categories : Unix

Why does ncat -exec work with a shell script but not with a perl script?
Does stopping the buffering (autoflush) of the standard output help? Add the following at the start of your Perl's cat: $| = 1; You may optionally precede this with select STDOUT; if your code did anything funky before that, but for your 3 line test script it's not needed.

Categories : Perl

How to capture the exit code of a shell script in a perl script?
You can check the exit code of another process with the child error variable $?. For example: system("perl foo.pl"); my $exit_val = $? >> 8; # now contains the exit value of the perl script Read the documentation for more info.

Categories : Perl

Retrieve exit status from php script inside of shell script
The $output parameter of the exec command can be used to get the output of another PHP program: callee.php <?php echo "my return string "; echo "another return value "; exit(20); caller.php <?php exec("php callee.php", $output, $return_var); print_r(array($output, $return_var)); Running caller.php will output the following: Array ( [0] => Array ( [0] => my return string [1] => another return value ) [1] => 20 ) Note the exit status must be number in the range of 0-254. See exit for more info on return status codes.

Categories : PHP

ImportError when calling python script via a shell script
I had a similar problem. It turned out that in my bash script I was running the Python script with a different version of Python than I was on the command line (my env was set up with virtualenv on Python 2.7 but I was calling the script with Python3 from the bash script). There is nothing in your snippets indicating this is the case but it is worth checking to make sure that the Python versions match up.

Categories : Python

use gimp color-to-alpha script in a shell script
Ok, I have found the awnser to my post. What I was doing was pretty much wrong all the way :p So here is a batch command line that removes black baground from an image like the color-to-alpha function of GIMP : /Applications/GIMP.app/Contents/MacOS/gimp -i -b "(let* ( ( image (car (file-png-load 1 "/Users/Name/Desktop/img.png" "/Users/Name/Desktop/img.png") ) ) (drawable (car (gimp-image-active-drawable image) ) ) ) (plug-in-colortoalpha 1 image drawable '(0 0 0) ) (gimp-file-save RUN-NONINTERACTIVE image drawable "/Users/Name/Desktop/img2.png" "/Users/Name/Desktop/img2.png") ) " -b "(gimp-quit 0)" It is quite incomprehensive like this because it needs to be an inline command but it works fine on my MAC

Categories : Osx

Don't want php script to execute the shell command as apache user when it is executed through browser?
Sudo normally requires an interactive shell to enter your password. That's obviously not going to happen in a PHP script. If you're sure you know what you're doing and you've got your security issues covered, try allowing the Apache user to run sudo without a password, but only for certain commands. For example, adding the following line in your sudoers file will allow Apache to run sudo without a password, only for the gzip command. nobody ALL=NOPASSWD: gzip Adjust the path and add any arguments to suit your needs. Caution: There might still be complications due to the way PHP calls shell commands. Remember that it's very risky to allow the web server to run commands as root! Another alternative: Write a shell script with the suid bit to make it run as root no matter who calls i

Categories : PHP

shell script to run multiple scripts from different shells
I don't have rosh and I don't have a man page for rosh but a similar problem exists with ssh: ssh localhost /bin/bash -c 'echo x' # (prints nothing) ssh localhost "/bin/bash -c 'echo x'" # x ssh localhost "/bin/bash -c 'tty'" # not a tty ssh -t localhost "/bin/bash -c 'tty'" # /dev/pts/12 Connection to localhost closed. ssh localhost "/bin/bash -c 'su - $USER'" # su: must be run from a terminal ssh -t localhost "/bin/bash -c 'su - $USER'" the last asked for a password and then gave me a shell, so that would be 2 of 3 steps. so one idea is to see if rosh has the -t option, too and the other is to enclose /bin/bash... with quotes, too (will require some escaping for the 3rd level). What does rosh say with equivalent commands? UPDATE latest state: rosh -n $host -l abcd -t "/bin/sh -c '

Categories : Shell

Can I program to chose a free CPU, I have multiple, to run my shell script?
I recommend GNU Parallel: GNU parallel is a shell tool for executing jobs in parallel using one or more computers. A job can be a single command or a small script that has to be run for each of the lines in the input. The typical input is a list of files, a list of hosts, a list of users, a list of URLs, or a list of tables. A job can also be a command that reads from a pipe. GNU parallel can then split the input and pipe it into commands in parallel. In addition, use nice.

Categories : Shell

Opening terminal with multiple tabs using shell script
You should always (always!) use an array for building up argument lists in bash. That is: #!/bin/bash # ^^ this has to be bash, not /bin/sh, for arrays to work cmd=( gnome-terminal ) for ((i=0; i<5; i++)); do cmd+=( --tab-with-profile=Default -e "java RunRTSPClient" ) done "${cmd[@]}" This will give you the exact equivalent of running: gnome-terminal --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" ...which is what I understand that you want. Trying to build a complex command in a string causes Very Bad Things to happen; read http://mywiki.wooledge.org/Bash

Categories : Linux

Shell script for insert multiple records into a Database
Please notice that you need to pass the start and end parameters as input arguments to your script: #!/bin/sh start=$1 end=$2 while [[ $start -le $end ]]; do echo "insert into employee(empid, country, state) values(${start}, us, ca)" start=`expr $start + 1` done

Categories : Shell

How do you run multiple ruby files in conjunction in a shell script?
Have you tried using & and wait? ruby one.rb & ruby two.rb & ruby three.rb & ruby four.rb & wait ruby five.rb & ruby six.rb & ruby seven.rb & ruby eight.rb & http://tldp.org/LDP/abs/html/subshells.html

Categories : Ruby

Edit certain files in multiple directories using a shell script
Can you use find to match the user files ? e.g. find ./ -maxdepth 1 -name "user*" -exec script_that_does_text_replace.sh {} ; where script_that_does_text_replace.sh is the code you wrote above.

Categories : Bash

Insert Into Multiple Files in Windows shell script
@ECHO OFF SETLOCAL FOR /f "delims=" %%i IN ('dir /b *.xml') DO ( SET line2=Y ( FOR /f "usebackqdelims=" %%x IN ("%%i") DO ( ECHO(%%x IF DEFINED line2 TYPE Line2.txt SET "line2=" ) )>"%%~ni.lmx" ) GOTO :EOF This should work for you - but it will delete empty lines.

Categories : Windows

How to return a value from a shell script in a python script
use Subprocess.check_output instead of Subprocess.call. Subprocess.call returns return code of that script. Subprocess.check_output returns byte stream of script output. Subprocess.check_output on python 3.3 doc site

Categories : Python

Shell Script inside perl script
Is this what you are looking for? $exec_string = <<EXEC; echo this is my shell script ls > tmp1 ls > tmp2 EXEC system($exec_string) EXEC can be substituted by any word (e.g. SHELL, SCRIPT, whatever).

Categories : Perl



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.