Bonjour,
Je souhaiterais exécuter un script CGI en console.
Ce scripts est generalement lancer via l'interface web et se rappelle lui même en version console .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
my @names = $query->param;
 
if (scalar(@names)>1) { #when add is pressed	
	print "Content-Type: text/html\n\n";
 
	if ($query->param('daily')){ # insert ncbi daily file(s) tblout
		treat_param_daily_case();			
	}else{ # genome part (for run new genome or insertion of genome tblout; one/many file(s) can be launch in the same time )
	    write_param_to_launch_console();
	}		
    print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=cazy_views.cgi\">";
}else{
	## batch part 
getopts("ldwm:t:uhs:f:g:");
 
    if ($opt_d){# daily file case
    	my $daily_info_file =$opt_t;
		launch_multiple_daily($daily_info_file);				
    }elsif ($opt_l){# launch multiple file to run new genome (modassign) || to insert tblout (insert_genome)
    	my $authorized = $opt_m;
    	my $no_insert =1 if ($opt_u);
    	my $with_hmm =1 if ($opt_h);
    	my $tblout=1 	if ($opt_t);
		launch_multiple_genomes($authorized,$tblout,$no_insert,$with_hmm);
 
	}elsif ($opt_w){# tblout insertion from command line
    	my $source  = $opt_s;
		my $geno_info  = $opt_g;
		my $fa_file = $opt_f;
		my $authorized = $opt_m;
		my $tblout =$opt_t;	
		process_insert($source,$geno_info,$fa_file,$authorized,$tblout);	
 
	## web part, display form	
	}else{
    	$manage = HTML::Template->new(filename => '../htmltemplate/content_insert_genome.tmpl');
	    $manage->param(TITLE => $title);
	    $manage->param(DESCRIPT => $metadesc);
	    $manage->param(TBLOUT => 1) if ($query->param('tblout'));
	    if ($query->param('daily')){
	    	 $manage->param(DAILY => 1) ;
	    	 $manage->param(TITLE => "Insert Daily Tblout");
	    }
 
	    $manage->param(DIRSERVER => $$global{dirhttp_server});
	    print "Content-Type: text/html\n\n",$manage->output;        
	}   
}
concretement le web va traiter les infos grace a write param_to_launch_console
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
sub write_param_to_launch_console{	
	my $usr = $session->param('usr');
	my $authorized =	check_if_authorized($usr,"Insert Tblout FAILED");	
 
	# read all info from tmpl
	my @all_tax_id=$query->param('tax_id');
    my @organism=$query->param('organism');
    my @strain=$query->param('strain');
    my @source=$query->param('source');
    my @fasta=$query->param('fasta_file');
	my @tblout=$query->param('tblout_file') if ($query->param('tblout'));
	if (!$query->param('tax_id') && !$query->param('organism')){
		my $msg =  "[WebJob] Run Job FAILED<BR> Please provide information<BR>";
		print $msg;
		exit(0);
   	}
 
	# write genome info (tax_id,organism ...) in a file (genome_info_file), will be read by the console version of the script  	
	my $str;
   	for(my $index=0;$index<scalar(@all_tax_id);$index++){   		
   		next if (!$all_tax_id[$index]&& !$organism[$index] && !$strain[$index] && !$source[$index] && !$fasta[$index]);
 
   		if ( !$fasta[$index] ){
   			# if file(s) not found send error msg to user			
		 	my $msg =  "No fasta_file for: ". $organism[$index]. "\n";
			print $msg;
			exit(0);
		}
		# write locally fasta_file passed by User
   		my $fasta_filename= write_file_in_tmp($fasta[$index]);		
   		$str .= $all_tax_id[$index]."\t".$organism[$index]."\t".$strain[$index]."\t".$source[$index]."\t".$fasta_filename;
 
   		 # write locally tblout_file (in case of tblout process/insertion ) passed by User
   		if ($query->param('tblout')){   			
   			if ( !$tblout[$index] ){
   				# if file(s) not found send error msg to user			 		
				my $msg =  "No tblout_file for: ". $organism[$index]. "\n";
   				print $msg;
				exit(0);				
			}
			# write locally fasta_file passed by User
   		  	my $tblout_filename=write_file_in_tmp($tblout[$index]);
   		  	$str.= "\t".$tblout_filename;
   		}   		
   		$str.= "\n";   		
   	}     	
 
   	my $first_name = $1 if($authorized=~/(\w+)\.\w+/);
   	open(LOCAL, ">".$$global{modassign_tmp}."/genome_info_file_".$first_name.".txt") or die $!; 
   	print LOCAL $str;
    close(LOCAL);	   
 
    my $cmd;
    if (param('tblout_file')){ # insert multiple genomes (multiple tblouts will be read and insert)
      	$cmd= "$$global{scripts}/privatesite/insert_genome.cgi -l -m '".$authorized."' -t 1 1>$$global{modassign_tmp}\/modass.log 2>&1&";    
    }else{ # run new genomes (multiple html will be generated )
    	my $no_insert = "-u" if $query->param('no_insert');
    	my $with_hmm = "-h" if $query->param('with_hmm');
    	$cmd= "$$global{scripts}/privatesite/insert_genome.cgi -l -m '".$authorized."' ".$no_insert." ".$with_hmm." 1>$$global{modassign_tmp}\/modass.log 2>&1&";
    }
    print $cmd;
	system ($cmd);
}
La commande lorsque je passe via www-data, pas de soucis ca marche.
Cependant, lorsque j'essaye de le lancer via cron : rien , pas de message d'erreur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
#!/bin/bash
 
date=`date +%Y_%m_%d`;
 
daily_info_file="/data/tmp/daily_info_file_$date.txt";
if [ -f $fichier ]
then
	cd /home/fripette/scripts/privatesite/
	perl insert_genome.cgi -d -t '$daily_info_file' >& /data/tmp/tblout_daily.log
fi
 
exit
Rien ne s'ecrit dans le tblout_daily.log.

Merci pour votre aide !
Frip'