Salome HOME
NRI : Rename Catalog according to rule (KERNELCatalog).
[modules/yacs.git] / bin / insertComputerRessourcesCatalog.sh.in
1 #!/usr/bin/perl -w
2 # Estelle Deville 14 sept 2001
3 # Utilities to complete the Ressource Catalog with a new computer ressource
4
5 print "What is the Ressource Catalog name (absolute path)? ";
6 chomp($catalog=<STDIN>);
7 print "What is the computer name? ";
8 chomp($computer=<STDIN>); 
9
10 printf "Will C++ container Type be able on %s [y/n]? ", $computer;
11 chomp($response=<STDIN>);
12 if($response eq "y")
13     {
14         push(@container,"C++");
15     }
16 printf "Will python container Type be able on %s [y/n]? ", $computer;
17 chomp($response=<STDIN>);
18 if($response eq "y")
19     {
20         push(@container,"python");
21     }
22 printf "Will NP container Type be able on %s [y/n]? ", $computer;
23 chomp($response=<STDIN>);
24 if($response eq "y")
25     {
26         push(@container,"NP");
27     }
28
29 chomp($working_computer=`hostname`);
30
31 if($working_computer eq $computer)
32 {
33
34     if(-r $catalog && -w $catalog)
35     {   #file exist and can bi read and write
36         chomp($OS=`uname`);
37         chomp($OS_version=`uname -r`);
38
39         $proc="/proc/cpuinfo";
40         if(-r $proc)
41         {
42             #information file of processor is accessible
43             open(PROC, $proc);
44             while(<PROC>)
45             {
46                 chomp;
47                 $temp = $_;
48                 $temp =~ s/\t.*$//;
49                 if($temp eq  "processor")
50                 {
51                     $_=~ s/^[^:]*: //;
52                     push(@proc_number,$_);
53                 }
54                 if($temp eq "model name")
55                 {
56                     $_=~ s/^[^:]*: //;
57                     push(@model_name,$_);
58                 }
59                 if($temp eq "cpu MHz")
60                 {
61                     $_=~ s/^[^:]*: //;
62                     push(@cpu,$_);
63                 }
64                 if($temp eq "cache size")
65                 {
66                     $_=~ s/^[^:]*: //;
67                     $_=~ s/ .*$//;
68                     push(@cache,$_);
69                 }
70             }
71             close(PROC);
72         
73         }
74         #Information Verification
75         for ($i=0; $i<=$#proc_number; $i++)
76         {
77             print "PROCESSOR\n";
78             printf "number %s \n", $proc_number[$i];
79             printf "model name %s \n", $model_name[$i];
80             printf "cpu %s \n", $cpu[$i];
81             printf "cache %s \n", $cache[$i];
82         }
83         print "OS information\n";
84         printf "OS %s \n", $OS;
85         printf "OS_version %s \n",$OS_version;
86         print "CONTAINER TYPE LIST\n";
87         for ($i=0; $i<=$#container; $i++)
88         {
89             printf "container type %s \n", $container[$i];
90         }
91
92         #Write catalog content
93         open(CATALOG_IN,$catalog);
94         $catalog_temp=$catalog."_temp";
95         open(CATALOG,">$catalog_temp");
96         $tmp =0;
97         while(<CATALOG_IN>)
98         {
99             print CATALOG $_;
100             if($_ eq "<Ressources-list>\n")
101             {
102                 $tmp=1;
103             }
104             if ($tmp == 1)
105             {
106                 print CATALOG "\t<computer>\n";
107                 printf CATALOG "\t\t<name>%s</name>\n", $computer;
108                 printf CATALOG "\t\t<OS>%s</OS>\n", $OS;
109                 printf CATALOG "\t\t<OS-version>%s</OS-version>\n", $OS_version;
110                 print CATALOG "\t\t<proc-list>\n";
111                 #processor
112                 for ($i=0; $i<=$#proc_number; $i++)
113                 {
114                     printf CATALOG "\t\t\t<proc>\n";
115                     printf CATALOG "\t\t\t\t<number>%s</number>\n", $proc_number[$i];
116                     printf CATALOG "\t\t\t\t<model>%s</model>\n", $model_name[$i];
117                     printf CATALOG "\t\t\t\t<CPU-MHz>%s</CPU-MHz>\n", $cpu[$i];
118                     printf CATALOG "\t\t\t\t<cache>%s</cache>\n", $cache[$i];
119                     printf CATALOG "\t\t\t</proc>\n";
120                 }
121                 print CATALOG "\t\t</proc-list>\n";
122                 #container
123                 print CATALOG "\t\t<containertype-list>\n";
124                 for ($i=0; $i<=$#container; $i++)
125                 {
126                     printf CATALOG "\t\t\t\t<containertype>%s</containertype>\n", $container[$i];
127                 }
128                 print CATALOG "\t\t</containertype-list>\n";
129                 print CATALOG "\t</computer>\n";
130                 $tmp=0;
131             }
132         }
133         close(CATALOG);
134         close(CATALOG_IN);
135         rename($catalog_temp,$catalog) || die "can't rename :$!";
136     }
137     else
138     {
139         printf "Error, the Ressource catalog %s isn't accessible\n", $catalog;
140     }
141
142 }
143 else
144
145     printf "Error, you should run the script on computer %s \n", $computer;
146 }
147
148
149