shell

Renaming a set of files to 001, 002, ... on Linux

I originally had a set of images of the form image_001.jpg, image_002.jpg, ... I went through them and removed several. Now I'd like to rename the leftover files back to image_001.jpg, image_002.jpg, ... Is there a Linux command that will do this neatly? I'm familiar with rename but can't see anything to order file names like this. I'm...

Capturing stdout when calling Runtime.exec

When experiencing networking problems on client machines, I'd like to be able to run a few command lines and email the results of them to myself. I've found Runtime.exec will allow me to execute arbitrary commands, but Collecting the results in a String is more interesting. I realize I could redirect output to a file, and then read fro...

Grep Recursive and Count

Need to search a directories with lots of sub-directories for a string inside files: I'm using: grep -c -r "string here" * How can I total count of finds? How can I output to file only those files with at least one instance? ...

How do I use PHP CLI to automate FTP when I don't have access to PHP's native FTP handle?

I'm writing an automation script on a production server that, among other things, needs to grab a list of remote files via FTP (FTP is the only option for interacting with the remote filesystem) and selectively download them. Why I can't use PHP's native FTP wrappers This is a production server in a very brittle environment. I'm writi...

Why does this sed command do nothing inside a bash script but work outside?

# join pairs of lines side-by-side (like "paste") sed '$!N;s/\n/ /' The above script comes from the great list of sed one-liners found on sourceforge. I wish to use it in an a bash script but it has no effect if used inside the script. If I pipe the output of the script through it, it joins join pairs of lines side-by-side as descri...

Django without shell access

Is it possible to run django without shell access? My hoster supports the following for 5€/month: python (I assume via mod_python) mysql There is no shell nor cronjob support, which costs additional 10€/month, so I'm trying to avoid it. I know that Google Apps also work without shell access, but I assume that is possible because of...

Why is Windows 'Run:' different from CMD line?

When I type 'http://www.google.com at the Windows Run: prompt it launches my default browser. But when I do it at the CMD or Commnad prompt it does not. I assume that there is some form of RunDLL command being issued but I can't find out what. Does anyone have any insight? ...

How to capture your username on Box A after you have ssh’d onto Box B?

Hi, Maybe not the best worded question, but hopefully it's a straightforward problem. The scenario is ssh'ing from a personal account on box A to a generic account on box B. The script running on box B needs to capture the personal account name for logging purposes. Is there any way of capturing this, either via ssh itself or some in...

How to extract a substring matching a pattern from a Unix shell variable

I'm relatively new to Unix shell scripting. Here's my problem. I've used this script... isql -S$server -D$database -U$userID -P$password << EOF > $test exec MY_STORED_PROC go EOF echo $test To generate this result... Msg 257, Level 16, State 1: Server 'MY_SERVER', Procedure 'MY_STORED_PROC': Implicit conversion from datatype 'VARCHA...

BASH blank alias to 'cd'

I am a happy BASH user. I do not want to switch to another shell (in this case ZSH). ZSH has this ability to change a directory without necessarily typing: cd /to/a/directory What would the correct alias (or maybe BASH function) to change directories without having to type 'cd'? On my above example, moving to /to/a/directory would b...

bash script to ssh into a box and get me to a python shell

I want to write a script that will get me straight to a python shell on another box so that i don't have to first run ssh and second run python. When I do "ssh hostname python" it just hangs - it's something to do with the fact that python is interactive. "ssh hostname cat x" works fine. Is there some ssh option that will make this wor...

Use Flash as shell to load Flex app and pass URLVars?

I am having a problem with preloaders showing up in my flex apps. I never had this problem when developing flash apps so I got the idea to use a flash app as a shell with the sole purpose of showing a preloader while the flex app loads. I am not sure how to do this though, and I also need to ba able to pass the FlashVars from the shell f...

How to parse XML in Bash?

Ideally, what I'd like to be able to do is: cat xhtmlfile.xhtml | getElementViaXPath --path='/html/head/title' | sed -e 's%(^<title>|</title>$)%%g' > titleOfXHTMLPage.txt ...

How can I remove everything except listed files with the Find-command?

I have a list of hidden files in a file "list_files" that should not be removed in the current directory. How can remove everything except them with a Find-command? I tried, but it clearly does not work: find . -iname ".*" \! -iname 'list_files' ...

How does the AND-operator work in the FIND-command?

My last question expanded, so let's analyse things separately. AND-operater, Intersection? I will give an example: $ find . | awk -F"/" '{ print $2 }' .zcompdump .zshrc .zshrc_copy .zshrc_somequy .bashrc .emacs $ find ~/bin/FilesDvorak/.* -maxdepth 0 | awk -F"/" '{ print $6 }' .bashrc .emacs .gdbinit .git .profile When I save the...

HTML to text conversion in shell script

I wrote a shell script to convert HTML source to plain text using lynx. Here it is: #!/bin/sh if [ -f = "/usr/bin/lynx" ] then if [ -f = "$1" ] then lynx -dump $1 > $2 else echo "File $1 does not exist!" fi else echo "Lynx is not installed!" fi Now, although lynx exists in the right direct...

How can I make a shell script using Perl?

I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f -exec perl -p -i -e "s/$search/$replace/g" {} \; The script does not get loaded. This suggests me that my script is wrong. How can you make a shell script using Perl? ...

How to attach a file using mail command on Linux?

I'm on a server running a Linux shell. I need to mail a simple file to a recipient. How to do this, prefereably using only the mail command? UPDATE: got a good solution, using mutt instead: $ echo | mutt -a syslogs.tar.gz [email protected] ...

Determining whether explorer.exe runs as a windows shell?

I need to make sure that explorer.exe runs as a system shell. What I need to do is: Overwrite the current shell (Winlogon\Shell) with explorer.exe Run explorer.exe (as shell) Overwrite the current shell with my own shell. Between the last two steps is a race: If I overwrite the current shell with my own shell too quickly, only "My ...

sed beginner: changing all occurrences in a folder

I need to do a regex find and replace on all the files in a folder (and its subfolders). What would be the linux shell command to do that? For example, I want to run this over all the files and overwrite the old file with the new, replaced text. sed 's/old text/new text/g' ...