w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
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

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

Conversion of shell script to python script
It looks like you're after a templating engine, but if you wanted a straight forward, no thrills, built into the standard library, here's an example using string.Template: from string import Template with open('a.html') as fin: template = Template(fin.read()) print template.substitute(name='Bob') # <head>Bob</head> I thoroughly recommend you read the docs especially regarding escaping identifier names and using safe_substitute and such...

Categories : Python

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

Why does this work in the Python IDLE shell but not when I run it as a Python script from the command prompt?
As @Sukrit Kalra says, don't use datetime.py as your file name. Python is getting confused with which datetime is which (and is importing itself!). Maybe; $ mv datetime.py my_datetime.py

Categories : Python

Python script to run shell command
Why are you using subprocess? A common practice to run Scrapy from a script is to use twisted's reactor. Taken from docs: from twisted.internet import reactor from scrapy.crawler import Crawler from scrapy.settings import Settings from scrapy import log from testspiders.spiders.followall import FollowAllSpider spider = FollowAllSpider(domain='scrapinghub.com') crawler = Crawler(Settings()) crawler.configure() crawler.crawl(spider) crawler.start() log.start() reactor.run() # the script will block here There is plenty of examples out there: Running scrapy from script (beginner) How to run Scrapy from within a Python script Running Scrapy from a script - Hangs Scrapy crawl from script always blocks script execution after scraping Hope that helps.

Categories : Python

use python script in shell (like fabric)
You can make your script start with the line: #!/usr/bin/env python Or, depending on your version: #!/usr/bin/env python3.3 Then you must make your script executable with a chmod, and it should work like you want!

Categories : Python

The script which runs python in shell
It's not a python script you can simply get and modify as any .py file. In order to play around with interactive interpretter you will have to download the python sources and go through them, as it's a build-in part of it (for performance sake). You can read up the details on http://docs.python.org/devguide/

Categories : Python

Script doesn't want to run from python shell
Use execfile: >>>execfile('clean_index.py') or just run it directly (not within the python shell): $ python clean_index.py assuming you have python in your path. Or, use an import in the python shell: >>>import fibo >>>fibo.fib(1000) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Module import sample taken from the docs. The filename is fibo.py. Since you probably simply want to run the file, I suggest you use the second option.

Categories : Python

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

Execute Shell Script from python with variable
Like this ? subprocess.call(['test.sh', str(domid)]) Documentation is available on the python website

Categories : Python

shell start / stop for python script
It is because ps aux |grep SOMETHING also finds the grep SOMETHING process, because SOMETHING matches. After the execution the grep is finished, so it cannot find it. Add a line: ps aux | grep -v grep | grep YOURSCRIPT Where -v means exclude. More in man grep.

Categories : Python

submit each line to a python script using shell.
This is a shell scripting question more than it is a python one. However, I think your issue is " > test.txt" the ">" will start from a blank file each time instead of appending the results. try " >> test.txt"

Categories : Python

Capture value from shell script and use it in Python without using subprocess
Try commands module for py2.3.4, note that this module has been deprecated since py2.6: Use commands.getoutput: import commands answer = commands.getoutput('./a.sh')

Categories : Python

How to run a python script from IDLE interactive shell?
The IDLE shell window is not the same as a terminal shell (e.g. running sh or bash). Rather, it is just like being in the Python interactive interpreter (python -i). The easiest way to run a script in IDLE is to use the Open command from the File menu (this may vary a bit depending on which platform you are running) to load your script file into an IDLE editor window and then use the Run -> Run Module command (shortcut F5).

Categories : Python

python run shell script that spawns detached child processes
Just some background on the methods I've tried to solve my above problem, before I go on to the answer proper: subprocess.call subprocess.Popen execve the double fork method along with one of the above (http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/) By the way, none of the above worked for me. Whenever I killed off the web application that executes the bash script (which in turns spawns some background processes we shall denote as Q now), the processes in Q will in a round-robin fashion, take over the port occupied by the web application, so I had to kill them one by one before I could restart my web application. After many days of living with this problem and moving on to other parts of my project, I thought of some random Stack Overflow posts and other

Categories : Python

How can I sort tuples by reverse, yet breaking ties non-reverse? (Python)
Just using sorted should suffice >>> sorted(results) [('10', 'George'), ('10', 'Mary'), ('9', 'Adam'), ('9', 'Frank'), ('9', 'John')] default cmp function checks precedence of a tuple by comparing each member of tuple, from 0 to n, in that order

Categories : Python

Read traffic light from Router to simulate lights on python/shell script
A very common way of monitoring router status is by using snmp. As a summary, for a small home router, it involves at least the following steps: Enable snmp in your router (this usually is only setup "snmp communities", they are the passwords for reading and writing). If your router allows it, I recommend to you to add an IP filter as well for filtering from what IP addresses snmp queries are allowed. Read SNMP OIDs (for instance, interface status list, interface usage stats, etc), you can use snmpwalk for testing. Once you can read standard values with snmpwalk you can load your router MIB file into your local MIB files repo (that enables you to read specific attributes from your router manufacturer). Setup your monitoring software (nagios is a very popular one). As you said you will us

Categories : Python

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

Why is my python script that runs the adb shell monkey command crashing for large values of events?
This might be your problem, but it's hard to tell without more information… You've given the subprocess a pipe, but you don't read from it until after it's finished. The warning in the docs explains why this is bad: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. It makes perfect sense that it would work for small numbers of commands—when there's not enough data to fill the pipe buffer—but hang for larger numbers. Looping around poll instead of calling wait doesn't help anything; all it does is burn 100% CPU for no reason. You're still not reading from the pipe. And calling communicate after the process

Categories : Android

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

Running a login shell using sudo inside a shell script on Mac OSX
Your shell is interpreting the $HOME variable in the heredoc, before the input reaches the su shell. You need to escape the $: bash-3.2$ sudo su -l root <<EOF > echo $HOME > echo $HOME > EOF /Users/kevin /var/root The real question is why does it work on your Linux box.

Categories : Osx

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

Use shell script wrapper to enter commands into a new shell
If the sequence of commands is fixed (does not change from run to run), you might be able to use: #!/bin/sh Dbm2 <<EOF table THE_TABLE ...other commands... EOF ls # Just to demonstrate that the shell continues The <<EOF notation is a here-doc. The lines up to the line containing EOF are the input to the command Dbm2. If the content of the commands needs to vary, you may be able to pipe the input to Dbm2. In your script, if you manually enter commands to Dbm2 and then quit, your original shell script should continue. The table THE_TABLE line would be treated as another shell command and would, most likely, fail.

Categories : Shell

How can I execute a shell-script in a Bash sub-shell?
You can do the same but without eval. with-env-overrides() { ( source $HOME/.env-overrides "$@" ) } Example: $ cat ~/.env-overrides export A=1000 $ export | grep ^A= $ with-env-overrides export | ^grep A= declare -x A="1000" As you can see, in the second case, you've got an environment with the A variable.

Categories : Linux

How to pass several shell variables to awk in shell script?
ls -l | nawk -v r="3,5" 'BEGIN{split(r,a,",")}{for(i in a)printf $a[i]" ";print " "}' Now you can simply change your r variable in shell script and pass it on. or you can configure it in your shell script and use r=$your_list_var What ever fields numbers are present in $your_list_var will be printed by awk command. The example above print 3rd and 5th fields of ls -l output.

Categories : Linux

Piping to running socat process, But how is this done?
Something like this: http://www.thegeekstuff.com/2010/07/perl-tcp-udp-socket-programming/ #!/usr/bin/perl #tcpclient.pl use IO::Socket::INET; # flush after every write $| = 1; my ($socket,$client_socket); # creating object interface of IO::Socket::INET modules which internally creates # socket, binds and connects to the TCP server running on the specific port. $socket = new IO::Socket::INET ( PeerHost => '127.0.0.1', PeerPort => '5000', Proto => 'tcp', ) or die "ERROR in Socket Creation : $! "; print "TCP Connection Success. "; # read the socket data sent by server. $data = <$socket>; # we can also read from socket through recv() in IO::Socket::INET # $socket->recv($data,1024); print "Received from Server : $data "; # write on the socket to server. $data = "DATA

Categories : Perl

using socat to multiplex incoming tcp connection
I found ncat ( http://nmap.org/ncat/) to be flexible and easier to use. I suggest you give it a try. I cannot currently test it for you to find the exact command, but you can let it listen on 2 ports; for one port you use the -k option to accept multiple clients.

Categories : Misc

Variables scope in inline django shell, vs python shell
It seems to be a known issue and fixed in Django 1.6. For the time being, there is a suggested workaround in the ticket. "Grab the following lines (from here https://github.com/django/django/blob/master/django/core/management/commands/shell.py) and replace the current implementation (...) with this": def ipython(self): try: from IPython.frontend.terminal.ipapp import TerminalIPythonApp app = TerminalIPythonApp.instance() app.initialize(argv=[]) app.start() except ImportError: # IPython < 0.11 # Explicitly pass an empty list as arguments, because otherwise # IPython would use sys.argv from this script. try: from IPython.Shell import IPShell shell = IPShell(argv=[]) shell.mainloop

Categories : Python

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

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

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

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

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

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

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

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

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

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



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