LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-09-2012, 09:00 PM   #1
hd1080
LQ Newbie
 
Registered: Dec 2008
Posts: 16

Rep: Reputation: 0
cgi script -- sending process to background


I'm newer to bash/cgi scripts, and could certainly use a hand with what I'm trying to do. I have a home server, and want to allow client computers to issue commands to it. I've done this successfully through cgi scripts.

However, what I'm trying to do now, is take these scripts and send a process to the background, so to speak. For instance, initiating a backup, and then printing something to the user immediately. Instead, right now, it won't go the next line of code until the current process is finished.

Here's an example. Again, I'm newer to this, so I know it might be a bit of a hack job. If there's a more efficient way to code this, I'm all ears:

Code:
#!/bin/sh
printf "Content-Type: text/html"
echo
echo
echo "<HTML>"
echo "<HEAD>"
echo "</HEAD>"
echo "<BODY>"
echo "Dummy Text"
cp -a /foo /bar &
echo "working..."
echo "</BODY>"
echo "</HTML>"
It seemed like putting the & at the end of the cp line would throw it to the background, but it still won't go to the next line of code until the cp command is finished. Suggestions?
 
Old 06-10-2012, 04:27 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
While there's nothing wrong with using BASH scripts as CGI (I used them quite a lot) it's not a scripting language that you should want to use for more elaborate things unlike Perl, Python, Ruby or PHP. Also note that unless you enable unprivileged users to run their own CGI scripts (something you should be careful with even if you think you understand the security implications) the CGI runs with the privileges of the web server user which may or may not be enough to perform the tasks you want it to. As to your question: you could hand off the job to the 'at' service, echo commands to a job file in a directory watched by a watch daemon or inotify tools.

* If you're not that well-versed in BASH here's some help:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setting background image in cgi shell script rajib_145 Linux - General 1 05-18-2012 04:37 AM
[SOLVED] Pass Shell Script to Background Process tg0000 Linux - Newbie 8 11-04-2011 12:53 PM
sending remote command to background process + out log c0m4r Linux - Newbie 6 02-02-2010 04:34 AM
Urgent : Regarding sending a current running process in background Ricky Linux - General 5 11-27-2007 02:07 PM
sending process to background Robert0380 Linux - General 5 12-31-2002 03:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration