Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to execute linux sh command from inside CF

Explorer ,
Mar 17, 2011 Mar 17, 2011

I am using CFMX 7,0,0,91690 Enterprise on Redhat Enterprise Linux 4.9 with Apache webserver 2.0.52.  I have a coldfusion template that queries from a Postgresql 8.0 database, copies the data from the queries into a set of files in one folder on the linux server, and then has a CFEXECUTE tag at the very end that calls a bash shell script on the same server. The shell script takes the files from the one folder, merges some of their content together, moves them to another folder, adds header and footer, and sets ownership and permissions.  These 2 scripts have been in place and working perfectly for several years now. No changes were made to content, permissions, or ownershop of scripts.  Suddenly last Friday the coldfusion script seems to have lost its ability to execute the shell script properly.  It does execute it and the shell script attempts to do some of the steps, but the resulting files are missing the content and have the linux environmental variables and their values displayed instead.  Clearly its getting an error but that is not being reported back to me. After the CF script ends, if I manually execute the shell script from the linux command line, it works perfectly. I tried giving it more permissions but that did not help.  Redhat support suggests I run the script with "sh -x" to get more detailed output for debugging, but I would need to do that from inside the CF script since that is where the problem is.  Is it possible to execute a shell script from inside a CF script using a linux "sh" command in some way (instead of the cfexecute, just so I can see debugging info)? Thanks in advance for any suggestions. Julie

TOPICS
Server administration
7.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 18, 2011 Mar 18, 2011

You could create a perl script that would run the SH command. Then instead of using cfexecute to kick off the pl job you could use cfhttp and have it dump the output after processing to see what's going on....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 21, 2011 Mar 21, 2011

We tried this, but we cannot get the coldfusion script to run the perl script either.  Basically the same problem.  The perl script calls the

bash script and executes fime from the command line, but cannot be executed from the coldfusion script.  After it runs the cfhttp variables say connection failure.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2011 Mar 21, 2011

Instead of executing the script, use CFEXECUTE to execute the shell, and pass the script (and -x and whatever else you want) as arguments.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 24, 2011 Mar 24, 2011

I tried your suggestion.  I ran the CF script with this at the end to try and execute the sh with argument -x for verbose and the name of the script:

<cfexecute name="sh" arguments="-x /bin/siscopy" outputfile="/home/coldfusion/sh_output.txt" timeout="600" />

it would not execute, kept giving me the error that my request was timing out, no matter how large I made the timeout attribute.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2011 Mar 24, 2011

I think you have to specify the name and file path of the executable:

<cfexecute name="/bin/sh" ...>

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 24, 2011 Mar 24, 2011
LATEST

Thanks for the suggestion, tried that too:

<cfexecute name="/bin/sh" arguments="-x /bin/siscopy" outputfile="/home/coldfusion/sh_output.txt" timeout="600" />

still didn't work.  Script ends with this coldfusion error: 

Timeout period expired without completion of /bin/sh

It does not complete the task of making the files, and the sh_output.txt file which is supposed to capture the -x output, is empty.

Thanks,

Julie

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources