0

I have 7 different .sh files, each one does a different thing, is mostly to diagnose a device. For example: FanPsu.sh this is the output

 FANs Status 
    FAN1A | 38h | ok | 29.96  | 11696 RPM   
    FAN1B | 39h | ok | 29.97  | 11868 RPM   
    FAN2A | 3Ah | ok | 29.98  | 11696 RPM   
    FAN2B | 3Bh | ok | 29.99  | 11954 RPM   
    FAN3A | 3Ch | ok | 29.100 | 11610 RPM   
    FAN3B | 3Dh | ok | 29.101 | 12040 RPM   
    FAN4A | 3Eh | ok | 29.102 | 11696 RPM   
    FAN4B | 3Fh | ok | 29.103 | 11954 RPM   

 PSUs Status 
    PSU Mismatch   | 17h | ns | 144.96 | Disabled   
    Status         | 52h | ok | 10.1   | Presence detected   
    Status         | 53h | ok | 10.2   | Presence detected   
    PSU Redundancy | 18h | ok | 144.96 | Fully Redundant 

Drives.sh , this is the output

 Check Drives Status 
    Slot Number        : 0   
    Drive's position   : DiskGroup 0  
    Media Error        : 0   
    Other Error        : 0   
    Predictive Failure : 0   
    Raw Size           : 558.911 GB [0x45dd2fb0 Sectors]
    Firmware state     : Online, Spun Up 
    Inquiry Data       : SEAGATE ST600MM0069 ST31WFJ0RVMG 
    Foreign State      : None   
    Media Type         : Hard Disk Device 
    Temperature        : 39C (102.20 F) 
    S.M.A.R.T alert    : No   

    Slot Number        : 1   
    Drive's position   : DiskGroup 0  
    Media Error        : 0   
    Other Error        : 0   
    Predictive Failure : 0   
    Raw Size           : 558.911 GB [0x45dd2fb0 Sectors]
    Firmware state     : Online, Spun Up 
    Inquiry Data       : SEAGATE ST600MM0069 ST31WFJ0R80Z 
    Foreign State      : None   
    Media Type         : Hard Disk Device 
    Temperature        : 39C (102.20 F) 
    S.M.A.R.T alert    : No   

    Slot Number        : 2   
    Drive's position   : DiskGroup 1  
    Media Error        : 0   
    Other Error        : 0   
    Predictive Failure : 0   
    Raw Size           : 5.821 TB [0x2e93432b0 Sectors]
    Firmware state     : Online, Spun Up 
    Inquiry Data       : SEAGATE XS6400LE70084 0001HSR032V2 
    Foreign State      : None   
    Media Type         : Solid State Device 
    Temperature        : 42C (107.60 F) 
    S.M.A.R.T alert    : No   

 Check Volumes Status 
    Name               : Virtual Disk0
    RAID Level         : 1 
    State              : Optimal 
    Number Of Drives   : 2 

    Name               : Virtual Disk1
    RAID Level         : 0 
    State              : Optimal 
    Number Of Drives   : 1 

So, I want to run one .sh file at a time, one after the other, in the order that I will provide, so at the end it will run each script and provide its output like if was a single .sh file. I dont want to run each .sh file at a time, I want to be able to run just ONE .sh file and it will execute all the .sh files.

1 Answer 1

1

There's nothing tricky about that. A shell script can execute other shell scripts. Assuming you've made the scripts executable (chmod a+x FanPsu.sh etc.) you can just do:

#!/bin/bash
FanPsu.sh 
Drives.sh
AnotherScript.sh
# etc.

Or if you haven't:

#!/bin/bash
bash FanPsu.sh 
bash Drives.sh
bash AnotherScript.sh
# etc.

Save that as another shell script (e.g., AllScripts.sh), make it executable (chmod a+x AllScripts.sh) and then run it.

There's pretty low overhead these days to having multiple instances of a shell interpreter running inside one another, but if you wanted for some reason to have a single instance, it's likely you could also just concatenate the scripts together, but possibly not depending on the precise contents, and they're probably easier to maintain as separate files anyway. Another alternative would be turn each script into a shell function and then source the files with the function definitions then call the functions. But there's really no need. A script running other scripts is perfectly fine.

If you want to stop the execution at any point if any of the scripts fail, etc., there are ways of making that happen by giving the right options to the shebang, or adding in conditions to the script calls; if you can't figure out how to do that, I'm sure someone here can explain.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .