shell-scripting

GUNZIP / Extract file "portion by portion"

Hi. I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thing even temporarily! No, this is just ONE super huge compressed file, ...

pdf2swf using MAC OS Batch command or Apple script

How do I write a batch process on the Mac for pdf2swf, I want to convert all pdfs in a folder into swf. But pdf2swf doesn't have a option to convert a folder of pdfs to swfs, you have to do it one at a time. I'm not sure how if I should use a Apple script or a Shell script, either one I'm not sure how to get or assign a file name variabl...

How to use parallel execution in a shell script?

I have a C shell script that does something like this: #!/bin/csh gcc example.c -o ex gcc combine.c -o combine ex file1 r1 <-- 1 ex file2 r2 <-- 2 ex file3 r3 <-- 3 #... many more like the above combine r1 r2 r3 final \rm r1 r2 r3 Is there some way I can make lines 1, 2 and 3 run in parallel instead of one after the anothe...

How to resume an ftp download at any point? (shell script, wget option)?

hi! i want to download a huge file from an ftp server in chunks of 50-100MB each. At each point, i want to be able to set the "starting" point and the length of the chunk i want. i wont have the "previous" chunks saved locally (ie i cant ask the program to "resume" the downlaod). what is the best way of going about that? i use wget mos...

Passing partial arguments in tcshell

Hey, I'm writing a shell script (tcsh) that is supposed to received 3 parameters or more. The first 3 are to be passed to a program, and the rest are supposed to be passed to another program. All in all the script should look something like: ./first_program $1 $2 $3 ./second program [fourth or more] The problem is that I don't know ...

how to add a function to that program, and call that function from the command line in the function

I have to add a custom function which shows currently running foreground and background processes launched by this shell. How do I define and call that function from the shell's command line? a#include "smallsh.h" /*include file for example*/ /*program buffers and work pointers*/ static char inpbuf[MAXBUF], tokbuf[2*MAXBUF], *ptr ...

How to partially ftp a file (using ftp, wget with shell scripts or php)?

hi, i want to partially download a ftp file. i just need to download lets say 10MB, but after skipping 100MB (for example). In php, http://php.net/manual/en/function.ftp-fget.php this function allows arbitay starting point: bool ftp_fget ( resource $ftp_stream , resource $handle , string $remote_file , int $mode [, int $resum...

How can I return a value from a Perl program to a Korn-shell script?

I want to do this in a shell script: #!/usr/bin/ksh PERL_PATH=/usr/local/bin/perl RET1=$(${PERL_PATH} missing_months_wrap.pl) echo $RET1 How do i do it? calling the perl script as above is giving me an error: > shell.sh Can't return outside a subroutine at missing_months_wrap.pl line 269. EDIT: inside the perl script the state...

read variables from file

Hi, I'm trying to write a shell script to backup websites, I've got it to go through each directory in vhosts and create a new directory vhosts/{siteurl}/private/backups/ and gzip up the site into there. However, I also want it to read a file from private that will contain database name, user and password. So I can then use these to p...

PHP system() help

Hello, I have this shell script #!/bin/sh ############################################################# # Example startup script for the SecureTrading Xpay4 client # # Install Xpay4 into /usr/local/xpay4 # # To run this script automatically at startup, place the # # following line at the end of the bootup...

How to do parrallel processing in Unix Shell script?

I have a shell script that transfers a build.xml file to a remote unix machine (devrsp02) and executes the ANT task wldeploy on that machine (devrsp02). Now, this wldeploy task takes around 15 minutes to complete and while this is running, the last line at the unix console is - "task {some digit} initialized". Once this task is co...

How to copy files from local machine to server using SSH file transfer protocol?

I have an Ubuntu 9.10 desktop machine which I use locally. I am setting up a server on a hosting provider. The server will run a very minimal version of Ubuntu server LTS (only LAMP and email server no GUI). I want to write a script (scheduled as a cron job) that will allow me to upload local files onto the server. I want to use [SFTP][...

MySQL bulk insert from CSV data files

I have some CSV data files that I want to import into mySQL. I would like to do the insert in a shell script, so that it can be automated. However, I am a bit weary of having the username and password in clear text in the script I have the following questions: I am uncomfortable with the idea of a uname/pwd in clear text in the scrip...

What is linux equivalent of running a .bat file on windows from PHP using system()

I have a PHP script that runs a .bat file on my windows machine using $result = system("cmd /C nameOfBatchFile.bat"); This sets some environmental variables and is used to call Amazon EC2 API from the command line. How do I do the same from a Linux server? I have renamed my .bat file to a shell (.sh) and changed the script to use 'ex...

FTP to SFTP in shell scripting

This script is to connect to different servers and copy a file from a loaction defined. It is mandatory to use sftp and not ftp. #!/usr/bin/ksh -xvf Detail="jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/ jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/" password=Unix11! c_filename=import.log localpath1=`pwd` for i in $Detail ...

Build won't complete when launching Java from Hudson "Execute shell"

As part of deployment of an application, I use Hudson to launch the built application on a remote release server. This is done by specifying a post build step using the "Execute shell" option. I copy a deploy.sh script to the remote server and execute it via ssh, e.g. scp /opt/myapp/deploy.sh myapp@myserver:/export/home/myapp/scripts/ ...

SSH login with expect(1). How to exit expect and remain in SSH?

So I wanted to automate my SSH logins. The host I'm with doesn't allow key authentication on this server, so I had to be more inventive. I don't know much about shell scripting, but some research showed me the command 'expect' and some scripts using it for exactly this purpose. I set up a script and ran it, it worked perfectly to login....

Using or in multiline sed replacement

hi folks I'm confused with a seeming simple part of sed - the or statement. I wrote the following sed which parses an event file with multiple events encapsulated between event tags and then prints the output of each event on 1 line each: machinename:~$ sed -n "/<event/,/<\/event>/ {/<result/{s/.*result value=\" \(.*\)\"\/>.*/\1/g; p};...

How to know from a bash script if the user abruptly closes ssh session

I have a bash script that acts as the default shell for a user loging in trough ssh. It provides a menu with several options one of wich is sending a file using netcat. The netcat of the embedded linux I'm using lacks the -w option, so if the user closes the ssh connection without ever sending the file, the netcat command waits forever....

shell scripting: nested subshell ++

Hi guys, more than a problem, this is a request for "another way to do this" actually, if a want to use the result from a previous command I into another one, I use: R1=$("cat somefile | awk '{ print $1 }'" ) myScript -c $R1 -h123 then, a "better way"is: myScript -c $("cat somefile | awk '{ print $1 }'" ) -h123 but, what if I h...