#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    running a C program that Call a long BASH code


    Error occur when running a program that Call a long BASH code within a C program

    root:~# ./test-small-network-sh
    sh: -c: line 2: syntax error: unexpected end of file
    sh: -c: line 2: syntax error: unexpected end of file
    sh: -c: line 2: syntax error: unexpected end of file
    sh: -c: line 2: syntax error: unexpected end of file
    sh: -c: line 2: syntax error: unexpected end of file

    ====================================

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <dirent.h>
    #include <signal.h>


    /********************************/

    int main()
    {
    system("if [[""$quotastat"" == """"]]; then echo ""off"" > /var/apache/quota.status fi");

    system("if [""$quotastat"" == ""on""]; then /sbin/quotaon -v /home else /sbin/quotaoff /home fi");

    system("if [[""$verify"" == """"]]; then "
    "/usr/local/sbin/test.sh "
    "echo ""done"" > /var/apache/verify "
    "fi");


    system("if [""$snmpvar"" == """"]; then "
    "cp /usr/local/sbin/snmpd.conf /etc "
    "fi");


    system("if [""$sysparam"" == """"]; then cp /usr/local/sbin/sysparam.conf /etc fi");
    }
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Er.. you should be escaping those double quotes " with a \, something like this \", not doubled quotes "".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Use \" instead of double quote and still have error


    I use \" instead of double quote "" and still have error

    root:~# ./test-small-network-sh
    sh: -c: line 2: syntax error: unexpected end of file

    ==============================
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <dirent.h>
    #include <signal.h>


    /********************************/

    int main()
    {
    system("if [[\"$quotastat\" == \"\"]]; then echo \"off\" > /var/apache/quota.status fi");

    }
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    My question is why are you trying to execute bash commands through the system function?
    Why not create a bash script file that executes these commands and call that script from the system function?

IMN logo majestic logo threadwatch logo seochat tools logo