Bug in C code
root:~# gcc -o test2 test2.c
root:~# ./test2 sh: -c: line 3: syntax error: unexpected end of file ============================ #include <stdio.h> main() { system("for i in `cat /etc/samba/smbpasswd|awk '{split($0,a,\":\"); " "if ((substr(a[1],1,1)!=\"#\") && (a[1]!=\"admin\")) print a[1]}'` " "do " "echo -n -e \"SMBUser\t\t\t$i\t\t\"`du -ks /home/$i | " "awk '{print (($1*1024)/1000000)}'`\"\n\" " "done"); } |
You can't concatenate strings like that. You will have to put all of the commands into a single string.
man strcat Also, it looks like you're trying to simulate hitting the "enter" key by ending the string. The shell/system call doesn't care about newlines; it ignores them. They're only provided as a means to make it more readable to people. To see what I mean, type out that sequence of commands like you would normally do at the command prompt. Execute it, and then hit the up arrow. Bash prints out the command all on a single line. That is what you will need to make your string look like when you feed it to the system command. |
why cant you concatenate strings like that? thats the way to continue strings over more than 1 line in C. the error i think is in the shell commands, instead of calling system print out the string and see of it prints what you actually mean to execute.
|
You're probably right kev. I just don't do it that way. I get "set in my ways" and if I see something that doesn't fit my coding style, I get antsy...
I'll go back into my little corner now... :) |
All times are GMT -5. The time now is 11:45 AM. |