View Full Version : Good cgi forum?
I have some cgi/perl questions and need a programmer's forum to ask these on. Does anyone know any good populated ones?
Sexxxboom
10-06-2001, 04:30 AM
Usually forums scripts bring an easy install.txt or readme.txt
You can compare & decide the best forum in: http://www.hotscripts.com/Perl/Scripts_and_Programs/Discussion_Boards/
good luck
Thanks, but I dont want a forum script. I want a forum that is already running to discuss cgi questions with other people.
WiredGuy
10-06-2001, 06:25 AM
Go ahead and post it here. There's lots of perl programmers around here that could probably help you out. Since the thread is already opened, make use of it :)
WG
Well ok. How do I run telnet commands from a cgi script?
So I want to tar a directory and copy it to another, how do run a command 'tar -rpf backup.tar folder', copy it to another folder 'cp backup.tar $newfolder' and untar it 'tar -xpf backup.tar' ? I know for sure it can be done.
Fossil
10-06-2001, 10:32 AM
its very easy in php i believe, i never used it
if you can use php its at:
http://www.php.net/manual/en/function.system.php
they say there its like the c function and since perl and c i think are similar, that maybe it
sorry i couldnt help more
salsbury
10-06-2001, 11:54 AM
system is correct. you can do it two ways (well, more than two, of course ;) )
#!/bin/sh
echo "Content-type: text/plain"
echo
tar -cpf backup.tar folder || exit 1
cp -p backup.tar newfolder || exit 1
cd newfolder && tar -xpf backup.tar || exit 1
echo "Completed successfully."
one major problem with this approach is that it quadruples the amount of space used (two backup.tar files, two folders). even if you remove the backup.tar files before, you'll need that space available some time.
a better approach, assuming you don't need the backup.tar file when you're done:
#!/bin/sh
echo "Content-type: text/plain"
echo
tar -cpf - folder | (cd newfolder && tar -xpf -)
echo "Completed successfully."
tihs will take advantage of unix pipes to transfer the data effectively through memory rather than disk. you'll still end up using double the disk space of just folder, but it sounds like that is okay.
also, fyi, you can make a "mirror" of another directory using symbolic links. if the directories are to be exactly the same in every respect, this will save you plenty of disk space and time (never have to copy the data over manually).
to do this, you'd run:
ln -s folder newfolder
salsbury
10-06-2001, 11:55 AM
Originally posted by salsbury:
<STRONG>system is correct. you can do it two ways (well, more than two, of course ;) )
</STRONG>
er. i wrote these in shell script rathern than perl. so system wasn't necessary here of course.
to convert it to perl is pretty easy.
"command" || exit 1
becomes
system ("command") || die;
change echo to print, and then you're done (basically :)
Thanks!
So the cgi script will look like this (more or less)?
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>
system ("tar -cpf backup.tar folder") || die;
system ("cp -p backup.tar newfolder") || die;
system ("cd newfolder && tar -xpf backup.tar") || die;
print "Done!"
print "/<HTML>
Would this work (with proper directories/ filenames etc.?
And let me give you another vote..! There.
salsbury
10-06-2001, 08:14 PM
[QUOTE]Originally posted by Hypo:
<STRONG>
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>
system ("tar -cpf backup.tar folder") || die;
system ("cp -p backup.tar newfolder") || die;
system ("cd newfolder && tar -xpf backup.tar") || die;
print "Done!"
print "/<HTML>
</STRONG>
add "; 's to the print lines that are missing them, but otherwise yeah that'll work. you could make it more verbose to help you diagnose problems if you wanted but i don't know if that's necessary for your application.
It appears to be working, but there's a slight problem. If I give relative paths, then it works, if I give absolute then it does not.
So from the cgi directory, this works -
cd path1/pathname/path
But this does not -
cd /home/htdocs/users/c00042/hypo/domain.com/html/cgi/path1/pathname/path
Any idea what might be the problem? Since i want to use it across multiple domains.
Also how do I print the command output on the html page? If that's not too complicated.
salsbury
10-07-2001, 12:04 PM
i'm not sure why cd would be failing with the full path - might be something specific to your host. i'd suggest trying each path component seperately until you narrow it down. also, you can try running system ("pwd"); to see the current directory, so you can better understand the full path.
you can get tar to be verbose by adding the '-v' flag. note that with text/html, this will put each file on the same output line unless you add PRE tags around it.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.