Complex Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex Script
# 1  
Old 10-01-2010
Complex Script

hey... i had a big problem with my professor

i have 3 simple archives

in.txt -> had all timestamps of users logon (100lines)
ex. 111111
222222
333333
out.txt -> had all timestamps of users logof (100lines)
ex. 111113
222225
333332
commands.txt -> timestamps anda the commands ofs de users (whatever)
ex.
111112
last >> last.txt
222223
other command
333333
another and another
i did a simple chinese

Code:
int in = 1   (lines of in.txt)
int out = 1 (lines of (out.txt)
int c = 1   (lines of commands.txt)

while ( in != end ){
    printf(logon = in / logout = out);
    while( c != end)
    {
        if ( c > in || c < out ) 
        {
            printf c+1;
            c+2;
        }
        else
            printf NO commands in this session;
            c+2;
    }
    in++;
    out++;
}

i try to ...

Last edited by Scott; 10-05-2010 at 02:24 PM.. Reason: Please use code tags
# 2  
Old 10-02-2010
What EXACTLY are you trying to accomplish? We see what you did.

Waht output do you want, for example?

Note - this looks like C shell. Not many people here are familiar with it because it has serious problems for use production systems.
# 3  
Old 10-02-2010
I'll try to explain better

history.txt ( the numbers is the timestamp under this is the command used)

1285875611
last
1285875780
history
1285871080
nano .bashrc
1285871000
history
1285871325
sudo su
1285865300
history


in.txt ( timestamps when the user started the session )

1285876440
1285875600
1285871580
1285871040
1285870860
1285870860
1285865100

out.txt ( timestamps when the user stoped to use )

1285876440
1285876140
1285871580
1285871100
1285870860
1285876380
1285868160

i need this

1285876440 :: 1285876440 .....................//is the same because is the current login
1285875600 :: 1285876140 ..................... //second line of in and out text
1285875611 last ...................................... //command used between the login
1285875780 history .................................. //command used between the login
1285871580 :: 1285871580 .....................//third line of in and out text
1285871040 :: 1285871100 ..................... //line 4 of in and out text
1285871080 nano .bashrc ......................... //command used between the login
1285870860 :: 1285870860 ..................... //line 5 of in and out text
1285870860 :: 1285876380 ..................... //line 6 of in and out text
1285871000 history .................................. //command used between the login
1285871325 sudo su .................................. //command used between the login
1285865100 :: 1285868160 ..................... //line 7 of in and out text
1285865300 history ................................. //command used between the login
# 4  
Old 10-03-2010
Code:
#!/usr/bin/env ruby  
# 1.9.1
f=File.readlines("history.txt")
f.each_with_index{|x,i| x.chomp!; f[i-1]<<" " << x and f[i]=nil if (i+1)%2==0}
f.compact!
g=File.read("in.txt").split
h=File.read("out.txt").split
comb=g.zip(h)
final=[]
comb.each do |x|
    final<<"#{x[0]} #{x[1]}"
    f.each_with_index do |com,ind|
        n,cmd=com.split
        n=n.to_i
        final<< com if n.to_i.between?(x[0].to_i,x[1].to_i)
    end
  end
puts final.uniq

Code:
$ ruby myscript.rb
1285876440 1285876440
1285875600 1285876140
1285875611 last
1285875780 history
1285871580 1285871580
1285871040 1285871100
1285871080 nano .bashrc
1285870860 1285870860
1285870860 1285876380
1285871000 history
1285871325 sudo su
1285865100 1285868160
1285865300 history

These 2 Users Gave Thanks to kurumi For This Post:
# 5  
Old 10-03-2010
I don't know how to explain how much do you help me !

thks a lot !!!!
# 6  
Old 10-05-2010
Really nice post , but I would like to suggest another technique using Perl:-

Code:
perl -wle '
open(IN , "<in.txt") or die "can not open$!\n" ;
open(OUT , "<out.txt") or die "can not open$!\n" ;
open(HIS , "<history.txt")  or die "can not open$!\n" ;
@in = <IN> ;
@out = <OUT> ;
@his = <HIS>  ;
close(IN) ;close(OUT) ;close(HIS) ;
chomp @in; chomp @out; chomp @his ;
%his=@his ;
for ($i=0 ; $i<=$#in ; $i++) {
                         if ($in[$i] == $out[$i]) {
                               print $in[$i],"  ",$out[$i]; next;
                               }
             map {
                          if ( $_ > $in[$i] && $_ < $out[$i] && $his{$_}) {
                                 print  $in[$i],"  ",$out[$i] if ( ! $flag ) ;
                                 print $_,"  ",$his{$_} ;
                                 delete $his{$_} ;
                                 $flag=1 ;
                                           }
                        } keys %his ;
         $flag=0 ;
}
'


SmilieSmilieSmilie

Last edited by ahmad.diab; 10-05-2010 at 02:02 PM..
This User Gave Thanks to ahmad.diab For This Post:
# 7  
Old 10-05-2010
thks ahmad.dias

nice one !

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Complex Bash Script

I have an FTP server with thousands of Invoices. All Invoices are in a folder called /volume1/MBSInvoices/ Monthly invoices are added to that folder every month. Here is a sample filename of the Invoices: invoice_1_20170101_10010052_10020052_10030052_JOHNDOE.pdf the Account ID is the... (6 Replies)
Discussion started by: badr777
6 Replies

2. Shell Programming and Scripting

Shell script to read little complex values

Dear All, I have attached a file. In that I want to read some of the values like 1. ExecutionTime 2. ClockTime etc. I want to read at a specified time. How can I do that? Thanks & Regards, linuxUser_ (9 Replies)
Discussion started by: linuxUser_
9 Replies

3. Shell Programming and Scripting

Complex calulation in shell script

Hi , I need one help to do some complex calculation in shell script. here is what i need to do:- a=2 b=2 c=2 d=2 result=a+(b/(20*c))+(c/(10*d)) is there any thing special there so that i can group intermdiate results. Please help me if you have any idea. (4 Replies)
Discussion started by: harpal singh
4 Replies

4. Shell Programming and Scripting

Complex transpose awk script

Hello to all in forum, Maybe an awk expert could help me with this complex task for me. I have the input shown below and I would like to get the output as follow: - I would like the output separated by commas. - The header is fixed and will be the same always. - For the lines containing... (22 Replies)
Discussion started by: Ophiuchus
22 Replies

5. Shell Programming and Scripting

Complex match of numbers between 2 files awk script

Hello to all, I hope some awk guru could help me. I have 2 input files: File1: Is the complete database File2: Contains some numbers which I want to compare File1: "NUMBERKEY","SERVICENAME","PARAMETERNAME","PARAMETERVALUE","ALTERNATENUMBERKEY"... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

6. Shell Programming and Scripting

awk script (complex)

picked this up from another thread. echo 1st_file.csv; nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } }' OFS=, 1st_file.csv *.csv | sort -r i need to use the above but with a slight modification.. 1.compare against 3 month... (25 Replies)
Discussion started by: slashbash
25 Replies

7. Shell Programming and Scripting

Complex coloring in script

My script prints lines in which the entire line may be colored, and portions may also be colored. e.g. Consider this to be one line: $red some text in red $yellow abcd $end_yellow red text 1234 $blue some text $end_blue more red text $end_red So using sed, I may based on condition 1,... (5 Replies)
Discussion started by: sentinel
5 Replies

8. Shell Programming and Scripting

complex find in script

How to I put my find command string into a script. It is currently to long to be entered manually at command line. for FNAME in `find /unixsxxx/interface/x.x/xxxxxx -type f \( -name '*.KSH' -o -name '*.sh' -o -name '*.sql' -o -name '*.ksh' \) -exec grep -il xxx.xxx.xxx.xxx {} \;`; do C=`grep -c... (5 Replies)
Discussion started by: TimHortons
5 Replies

9. Shell Programming and Scripting

Complex Insert block in the Script

I have script in that there are thousands of create statement... I want to add these lines, above every Create Stament ================================================ IF OBJECT_ID('dbo.account_account_relations') IS NOT NULL BEGIN DROP TABLE dbo.account_account_relations IF... (2 Replies)
Discussion started by: niceboykunal123
2 Replies

10. Shell Programming and Scripting

Need complex script, anyone up for a challenge?

Default shell is /usr/bin/zsh Script will be running #!/bin/bash Need to pull information from database while using other scripts already made (not by me). Ok, so i need a script pulling certain information about a customer's router interfaces. I am using a ROUTER-DNS-NAME as variable $1 I... (3 Replies)
Discussion started by: ///NNM
3 Replies
Login or Register to Ask a Question