Programming :: Control Execution Of Programs In A Shell Script?
Apr 27, 2010
Do you know how to write a shell script that executes say 4 instances of the same program in different directories at the same time, and once ONE instance completes it executes a new instance of that program in a new directoryd so on, until 100 instances have been executed, each in their own directory
Is it possible to have an Expect script spawn an SSH session, log in, then go into interactive mode and give control of the SSH session to a Bash script? Here's a simplified example of the script so far:
I have never set-up a chroot-jailed environment before and I am afraid I need some help to do it well.To explain shortly what this is all about: I have a webserver to which users send python scripts to process various files that are stored on the server (the system is for Research purpose).Everyday a cron job starts the execution of the uploaded scripts via a command of this kind: /usr/bin/python script_file.pyAll of this is really insecure and I would like to create a jail in which I would copy the necessary files (uploaded scripts, files to process, python binary and dependencies).
I already looked at various utilities to create jails but none of them seemed up-to-date or were lacking solid documentation (ie. the links proposed in How can I run an untrusted python script)Could anyone guide me to a viable solution to my problem? like a working example of a script that creates a jail, put some files in it and executes a python script?
i tried to execute wireless programs on NS2 i found errors like command not found! but i executed wired programs on the same successfully is their any paths that i should setup for executing wireless programs?
and also i tried a simple c program in fedora7 which executed successfully but when i tried same program on .cc extension and complied with g++ -g filename.cc i found errors like cannot link to g++....why?
i need to take the backup some folders encryption formate with password i used gpg encription in the script but it is not taking the password it throos errorthe syntax is#!/bin/bashtar -cvzf test.tar.gz target ; echo "test" | gpg -c test.tar.gz --stdin
I could run the script from terminal. My script invokes some installation and works fine.But my wish is that end-user should double click the sh script and it should run.But how? I got few links - but none was of was quite helpful
I want to use ssh to execute a command and to wait endlessly to log everything (in file) that comes as a stream of the connected server. But unfortunately, in the manual its written "If command is specified, it is executed on the remote host instead of a login shell"
So what happens is that when I specify my command: ssh user@server "my_command"
It executed the command and the flow of execution returns to bash shell. So basically my session ends right after the command is executed. This happens only in case I specify command in the command line. If I login into ssh manually and then type "my_command", then the session doesn't end. I want the ssh not to exit, because after "my_command" executes, I want to capture everything in the session.
And achieve something like this when I view the contents of test2.txt:
Hello World Your boss is Me
The problem is, it's not that easy to achieve. I don't want to do the "echo Hello $USER1 >> test2.txt" because I'm planning to implement this on a MB-sized text file.
I'm trying to save the output of the script I wanna run but for some reason I cant manage to do it with "script.sh > Output_4.txt"
The thing is that the script was already run and it extracted some directories so when I try to run it again (to save the log to a Output_4.txt) bash says (see screen-capture) and of course the log's empty!!!!
I went to an interview last week and there was this guy who asked a simple question that i have been trying to solve for a couple of days. I tried google but i just cant get the search keywords right. The result were just useless. Well, the question is : "How can we allocate a limited memory to a process before we start its execution" well, the question is related to an X11 system so may be some flags must be set to limit its memory.
In gui validation if user enters string in integer requiring field, a dialog box pops out. So on clicking the button i want to stop the program execution and return to the previous jframe(either the same one or newly created object of it).
How can i handle this in java. I tried calling main(); but it doesn't work. Also System.exit(0); doensn't work.
I have a bash script which is composed of different functions.I want to able to select which functions to be executed when i run the script, for that i thought about using a flag in the function. but i dont know how to skip the function whose flag is set to zero.
As part of my job I often have to write queries in Oracle (10g) and I am experienced enough to see where I should be using an index where possible etc. Most of the time I just let the CBO come up with the best plan however sometimes it obviously doesn't!Now, I know in general that full scans of large tables aren't good however I don't fully understand an execution plan - ie, I could not look at a complex piece of code, look at it's plan and say "oh, the reason that is performing badly there is because the SBO has chosen to use nested loops rather than a hash join, so if I hint it then it will run quicker!" - this ultimately is where I'm trying to get to
control keys aren't working most of the time in Open Office. I can copy, cut and paste with the mouse, but Control+C/X/V/Z is not working at all. I also use intellij idea, there I have the same problem, but I can use its own defined control+alt+space. I've tried Abiword, the control keys worked at the begging but then after a while when I used control+something(C/X/V/Z), it always selected everything. Besides that, the control keys are working perfectly in nautilus, terminal, firefox, chrome, gedit. I'm using Ubuntu 9.10.
I tried adding sample programs to the Control Center by adding them to the Preferences/Administration menu, but that doesn't work. I'm using Lucid Lynx.
I have a test framework written in tcl which i run for 5-6 hours.Now i want to retrieve the pid of the process (execution using framework) as first few line of the script and do some processing.
I'm trying to figure out how to continue execution of a Python program while a background task is going on.
In bash, it is adding "&" to the end as in:
Code: #! /bin/bash find / -iname "*.py" > /tmp/all_pys & echo "looking for all python scripts and putting them in /tmp/all_pys" (yes, I know I could just put the echo BEFORE the find but I just use it for example)
Say I do that in python (not necessarily running the shell, but perhaps using scriptutil.ffind or something similar), but want to allow the user to be doing something else while running that search in the background, how would I thread, fork, subprocess (not to be confused with the module and Popen) [or whatever I should call it] that?
I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.
Code: if [ $# -eq 0 ] ; then d=`pwd` for i in * ; do if test -d $d/$i ; then echo "$i:" code....
socat - exec:'bash -li',pty,stderr,ctty -> bash: no job control in this shell
What options should I use to get fully fledged shell as I get with ssh/sshd? I want to be able to connect the shell to everything socat can handle (SOCKS 5, UDP, OpenSSL), but also to have a nice shell which correctly interprets all keys, various Ctrl+C/Ctrl+Z, tab completion, up/down keys (with remote history).
- Found "setsid" socat option. It fixes "no job control". Now trying to fix Ctrl+D. - socat file:`tty`,raw,echo=0 exec:'bash -li', pty, stderr, setsid, sigint, sane. Not it handles Ctrl+D/Ctrl+Z/Ctrl+C well, I can start Vim inside it, remote history is OK.
Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?
Example:
Code:
>>> import subprocess >>> help(subprocess) ... [pages of stuff to read] ...
I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.
I'm setting up an Ubuntu server and I keep getting strange problems with my editor.I'm not sure if this is because my keyboard configuration is wrong or I screwed up the installation but regardless it's quite frustrating.
When using the movement keys (arrows and numpad) I get "[" brackets and "C"s, if I hold down or push down on the key hard a list of errors and text comes up, usually involving something that says something like:"Mount disabled" or "____ disabled press CONTROL-X to restart the shell"Similair problems are also found in vi (when in insert mode).I have been plagued with text editor problems and have need several reboots just to get out of a file, often because it just flat out stopped responding to keyboard commands.
I have a program that I run from the terminal that requires manual input (it's matlab in mex debugging mode, matlab -Dgdb, which starts the GNU C debugger with its own custom settings).
Every time I run this program I always type in the same few commands in the program's interactive shell before I actually start working (for example: run -nojvm; stop at mexFunction; continue). I want to avoid typing these commands and I thought I could do this with shell scripting, saving the commands in the mycommands file, then running: myprogram < mycommands
The problem is that this runs all the commands and then exits the program. I want it to run the commands and return control to me so I can run my commands. Is there a way to tell the shell to use a file or a string as the input to a program then immediately return control to the user without the exiting the program?
I've created a simple script based menu. This menu will be accessed by only a certain users via ssh.When user logs in, the menu will automatically run. (configured at user's .bash_profile).How do I force the session to close when user hits Ctrl-C or Ctrl-Break ?In a nutshell, I don't want user to have access to shell.
I recently started shell programming and my task now is to do a menu display.Currently i am stuck whereby user will input both title and author and it will delete it.
After an update today, my kernel got upgraded to kernel-2.6.34.8-6-default. With this update, my old initrd-2.6.34.7-0.7-default got removed and corresponding grub menu options also got removed. Now after reboot,I am dropped to a shell with the last message being "no job control in this shell". I cannot startx or change to init 5. In fact, the 'boot' partition is not mounted.Even the root partition ( LVM volume ) is not mounted. I guess there was some problem in the initrd creation. I do not know the reason.An earlier post with this title seems to think problem in fstab.But my fstab was not touched by the update. How to get back to normal desktop?
Is it possible to assist in the programming Shell Scripts Job: To send a message to the email,All orders written in Terminal or ssh example : ls , pwd , cat , and other
I'm working on my ncurses application, written in C. I get user input through a loop which uses getchar(). I was able to recognize Ctrl-n by comparing the keypress to ASCII character 16, and this seems to work fine. However, if I noticed that the ASCII character for Ctrl-j (10) is the same as the Line Feed. I tested this, and if I press enter on the keyboard I get the same ASCII value as when I press Ctrl-j.
So, what do I do if I want Ctrl-j to mean something different in my program than pressing enter?The ncurses terminal mode is set to raw, with a 100 millisecond timeout, and keypad is on (I'm already using the up and down arrow-keys).
I'm using expect to log into a remote server and run a script. I want to able to have expect edit the output from that script, on the remote server, in VI. Has anyone ever done this before, it seems as though the expect interpreter has nothing to expect once VI is started, the file pointer starts at the beginning of the line, and expect usually reads the characters before the pointer.
I've always thought that the idea was very cool, but I get restricted by the way distros think that "httpd" and the like are the only things that should go into a runlevel - I mean Fedora doesn't even let you turn off the GUI!I want to do some lower-level hacking than that, so can someone help me?