shell

How do I change my current directory from a python script?

I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named my_cd.py for now, should then effectively 'cd' the user to the chosen directory. Example of how this should wo...

Vim: Pipe selected text to shell cmd and receive output on vim info/command line

I want to pipe the selected text to a shell command and receive the one-line output from this shell command on the vim info/command line? What I'm really trying to do: Pipe the selected text to a pastebin-type shell command and I want to receive the output of the shell cmd (which is the http link to the pastebin). Is this possible? ...

Send mass emails php (probably a shell question?)

I've got 80,000 users on my site and i've recently turned away from the forum script i've been using and built something very simple myself that works just as well (the forum script was too bloated and resource intensive for my simple site) The only thing i've lost is the ability to mass email all my members. So i'm looking to come up ...

UNIX script to convert queries

I need a UNIX shell script to convert my queries from Java compatible to Oracle compatible format. ie. I have all the java compatible queries: java: SELECT a, b, c, d, e, f,g "+// "from test where year(timestamp)=year(today) and month(timestamp)=month(today) " +// "and day(timestamp)=2 and h='" + "W" + "'" Oracle SELEC...

execute a command

I have script file where a command is stored in a variable First i got the command (assume "ls -l " command) cmd=`cat /proc/2345/cmdline` now doing echo $cmd outputs ls -l Now how to use $cmd to actually execute that command. which is ls -l ...

generate a random file using shell script

How can i generate a random file filled with random number or character in shell script? I also want to specify size of the file. ...

Automatically execute commands on launching python shell.

Hi, I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. I would like to automatically import some modules so I don't have to type the whole shebang everytime I hop into the shell. Thanks, ...

How to redirect output from dd command to /dev/null ?

In shell script i need to redirect output from dd command to /dev/null - how to do that? ( dd if=/dev/zero of=1.txt count=1 ) 2>&1 /dev/null didn't work! ...

How to write a shell in Python

I've written a small console application that can perform certain tasks. The user interface is similar to things like version control systems or yum etc. So basically you can think of it as a domain specific language. Now I'd like to write a (bash like) shell that can execute and auto-complete this language and has a command history (so ...

Bash Shell Script: Nested Select Statements

I have A Script that has a Select statement to go to multiple sub select statements however once there I can not seem to figure out how to get it to go back to the main script. also if possible i would like it to re-list the options #!/bin/bash PS3='Option = ' MAINOPTIONS="Apache Postfix Dovecot All Quit" ...

why egrep's stdout did not go through pipe?

Hi, i got a weird problem regarding egrep and pipe I tried to filter a stream containing some lines who start with a topic name, such as "TICK:this is a tick message\n" When I try to use egrep to filter it : ./stream_generator | egrep 'TICK' | ./topic_processor It seems that the topic_processor never receives any messages However, wh...

Selecting Update queries alone from list of files using shell script

I am trying to get Update queries from a list of files using this script.I need to take lines containing "Update" alone and not "Updated" or "UpdateSQL"As we know all update queries contain set I am using that as well.But I need to remove cases like Updated and UpdatedSQL can anyone help? nawk -v file="$TEST" 'BEGIN{RS=";"} /[Uu][Pp][...

What environment variables available while starting the script using init.d boot process

My problem is like this (OS is Sun Solaris): 1) At the boot time I want to start a process using a specific script. I am doing this by putting this script in /etc/init.d (and following other K and S rules) 2) The program which will be called by the script is located at $HOME/xxx/yyy location. 4) I am using 'su - {myuser} -c "{full pat...

shell_exec() in PHP

<?php // Execute a shell script $dump = shell_exec('bigfile.sh'); // This script takes some 10s to complete execution print_r($dump); // Dump log to screen ?> When the script above is executed from the browser, it loads for 10s and the dumps the output of the script to the screen. This is, of course, normal. But if I want the dat...

Passing lines as args to a script

How do I pass each line from a text file as an argument to a script I have written? So each line is then in itself a single arg to the script each time. ...

Vb.Net Shell App - AutoRestartShell

We have a Vb.Net application that runs as the windows shell for certain users. We'd like the application to automatically restart when it crashes. The application is set as the shell here: HKEY_USERS*User*\Software\Microsoft\Windows NT\WinLogon\Shell I've tried adding an "AutoRestartShell" key with a value of "1", like what exists i...

Cheat sheet exhibiting bash shell stdout/stderr redirection behavior

Is there a good cheat sheet demonstrating the many uses of BASH shell redirection? I would love to give such a thing to my students. Some examples I'd like to see covered: cmd > output_file.txt #redirect stdout to output_file.txt cmd 2> output_file.txt #redirect stderr to output_file.txt cmd >& outpout_file.txt #redirec...

how to create shell script for logs

Hello everybody, I'm currently watching my log files like this tail -f and every now and then I press up key and hit return so new changes in log print into console, how to make it print itself when change in log file occur? Here is the requirement : START loop 1. Check file.log 2. If file.log has changed print the changes 3. else print...

Several ways to call a windows batch file from another one or from prompt. Which one in which case?

A windows batch file (called.bat or called.cmd) can be called from another batch file (caller.bat or caller.cmd) or interactive cmd.exe prompt in several ways: direct call: called.bat using call command: call called.bat using cmd command: cmd /c called.bat using start command: start called.bat I'm quite in trouble to differentiate th...

Bash Shell Scripting - return key/Enter key

I need to compare my input with enter key/return key... read -n1 key if [ $key == "\n" ] echo "@@@" fi But this is not working.. What is wrong with this code ...