Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 0fa287c

Browse files
committed
Lint shell scripts
1 parent 12a1c8d commit 0fa287c

40 files changed

+311
-218
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Check Shell Script Syntax
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2.2.0
11+
- name: Install ShellCheck
12+
run: |
13+
sudo apt-get install shellcheck
14+
- name: Lint with ShellCheck
15+
run: |
16+
shellcheck --shell=bash -x $(find ./ -iname "*.sh")

.github/workflows/check_syntax.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

CondorMonitoring/JobCounter.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
location="/afs/cern.ch/user/c/cmst1/CondorMonitoring"
99
outputdir="/afs/cern.ch/user/c/cmst1/www/CondorMonitoring/"
1010

11-
#Set environment
11+
# Set environment
12+
# shellcheck disable=SC1091
1213
source /data/admin/wmagent/env.sh
14+
# shellcheck disable=SC1091
1315
source /data/srv/wmagent/current/apps/wmagent/etc/profile.d/init.sh
14-
cd $location
16+
cd $location||exit
1517

1618
#Email if things are running slowly
1719
if [ -f scriptRunning.run ];
@@ -33,6 +35,6 @@ fi
3335
python JobCounter.py &> JobCounter.log
3436
exitstatus="$?"
3537
echo "JobCounter.py exit status: $exitstatus"
36-
cp *.json $outputdir
37-
cp *.txt $outputdir
38+
cp ./*.json $outputdir
39+
cp ./*.txt $outputdir
3840
rm scriptRunning.run

PhEDEXFix/phedex-fix.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/bash
22
./config/wmagent/manage execute-agent wmcoreD --shutdown --components=PhEDExInjector
33
./config/wmagent/manage mysql-prompt wmagent<querry.sql>lfns.txt
4+
# shellcheck disable=SC2002
45
cat lfns.txt | grep /store > lfnsgreped.txt
56
#tail -n 28 install/wmagent/PhEDExInjector/ComponentLog | head -n1 > phedex.log
67
#for j in $(for i in $(cat phedex.log) ; do echo $i | awk -F'"' {'print $2'} ; done | grep root) ; do echo $j; done > lfns.txt
78
./fileInPhedex.py lfnsgreped.txt > lfnsinPhedex.txt
9+
# shellcheck disable=SC2013
810
for i in $(cat lfnsinPhedex.txt); do echo "UPDATE dbsbuffer_file set in_phedex = 1 where lfn='$i';";done > meuscript.sql
911
./config/wmagent/manage mysql-prompt wmagent < meuscript.sql
1012
./config/wmagent/manage execute-agent wmcoreD --shutdown --components=PhEDExInjector
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
2+
# shellcheck disable=SC1091
23
source /data/srv/wmagent/current/apps/wmagent/etc/profile.d/init.sh
34
python2.6 /home/cmsdataops/storeResults/cronjobs/StoreResultsAddCMSSWReleases.py

Unified/exec_expose.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ loc=$4
55
dest=$5
66
short=$6
77

8-
echo "Parameters passed to execution:" $wf $p $er $loc $dest $short
8+
echo "Parameters passed to execution:" "$wf" "$p" "$er" "$loc" "$dest" "$short"
99

1010
#sudo -u cmst1 /bin/bash --init-file ~cmst1/.bashrc $loc/WmAgentScripts/Unified/expose.sh $wf $p $er $dest $short
11-
source $loc/WmAgentScripts/Unified/expose.sh $wf $p $er $dest $short
11+
# shellcheck disable=SC2034,SC1090
12+
source "$loc"/WmAgentScripts/Unified/expose.sh "$wf" "$p" "$er" "$dest" "$short"

Unified/expose.sh

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
host=`echo $HOSTNAME | cut -d "." -f 1`
4-
echo "looking for condor log on" $host
3+
host=$(echo "$HOSTNAME" | cut -d "." -f 1)
4+
echo "looking for condor log on" "$host"
55
taskName=$1
66
wmbsID=$2
77
code=$3
@@ -11,54 +11,55 @@ short=$5
1111

1212
#end_dir=/afs/cern.ch/user/c/cmst1/www/JobLogs/$taskName/$cluster/$host\_$wmbsID
1313
#end_dir=/afs/cern.ch/user/c/cmst2/www/unified/condorlogs/$taskName/$code/$cluster/$host\_$wmbsID
14+
# shellcheck disable=SC1001
1415
end_dir=$loc/condorlogs/$taskName/$code/$short/$cluster/$host\_$wmbsID
1516

1617
echo '==================================== Condor log retrieval ============================================='
17-
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/$taskName/*/job_$wmbsID/
18-
dir=`ls -d /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/$taskName/*/job_$wmbsID/`
19-
if [ -z $dir ]; then
18+
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/"$taskName"/*/job_"$wmbsID"/
19+
dir=$(ls -d /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/"$taskName"/*/job_"$wmbsID"/)
20+
if [ -z "$dir" ]; then
2021
echo "no on-going directory"
2122
else
22-
echo " Found some logs in" $dir
23-
echo "Will put it in " $end_dir
24-
mkdir -p $end_dir
25-
cp -r $dir/* $end_dir/.
23+
echo " Found some logs in $dir"
24+
echo "Will put it in $end_dir"
25+
mkdir -p "$end_dir"
26+
cp -r "$dir"/* "$end_dir"/.
2627
fi
2728
echo '==================================== Condor log retrieval ============================================='
28-
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/$taskName/*/*/job_$wmbsID/
29-
dir=`ls -d /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/$taskName/*/*/job_$wmbsID/`
30-
if [ -z $dir ]; then
29+
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/"$taskName"/*/*/job_"$wmbsID"/
30+
dir=$(ls -d /data/srv/wmagent/current/install/wmagent/JobCreator/JobCache/"$taskName"/*/*/job_"$wmbsID"/)
31+
if [ -z "$dir" ]; then
3132
echo "no on-going directory"
3233
else
33-
echo " Found some logs in" $dir
34-
echo "Will put it in " $end_dir
35-
mkdir -p $end_dir
36-
cp -r $dir/* $end_dir/.
34+
echo " Found some logs in" "$dir"
35+
echo "Will put it in " "$end_dir"
36+
mkdir -p "$end_dir"
37+
cp -r "$dir"/* "$end_dir"/.
3738
fi
3839

3940
echo '==================================== Condor log retrieval ============================================='
40-
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/${taskName:0:1}/$taskName/JobCluster_$cluster/Job_$wmbsID.tar.bz2
41-
file=`ls /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/${taskName:0:1}/$taskName/JobCluster_$cluster/Job_$wmbsID.tar.bz2`
42-
if [ -z $file ]; then
41+
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/"${taskName:0:1}"/"$taskName"/JobCluster_"$cluster"/Job_"$wmbsID".tar.bz2
42+
file=$(ls /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/"${taskName:0:1}"/"$taskName"/JobCluster_"$cluster"/Job_"$wmbsID".tar.bz2)
43+
if [ -z "$file" ]; then
4344
echo "no archived file"
4445
else
45-
echo " Found some logs in" $file
46-
echo "Will put it in " $end_dir
47-
mkdir -p $end_dir
48-
cd $end_dir
49-
tar xvf $file
46+
echo " Found some logs in" "$file"
47+
echo "Will put it in " "$end_dir"
48+
mkdir -p "$end_dir"
49+
cd "$end_dir"||exit
50+
tar xvf "$file"
5051
fi
5152

5253
echo '==================================== Condor log retrieval ============================================='
5354
cluster=${wmbsID:0:4}
54-
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/${taskName:0:1}/$taskName/JobCluster_$cluster/Job_$wmbsID.tar.bz2
55-
file=`ls /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/${taskName:0:1}/$taskName/JobCluster_$cluster/Job_$wmbsID.tar.bz2`
56-
if [ -z $file ]; then
55+
echo 'LISTING: ' /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/"${taskName:0:1}"/"$taskName"/JobCluster_"$cluster"/Job_"$wmbsID".tar.bz2
56+
file=$(ls /data/srv/wmagent/current/install/wmagent/JobArchiver/logDir/"${taskName:0:1}"/"$taskName"/JobCluster_"$cluster"/Job_"$wmbsID".tar.bz2)
57+
if [ -z "$file" ]; then
5758
echo "no archived file"
5859
else
59-
echo " Found some logs in" $file
60-
echo "Will put it in " $end_dir
61-
mkdir -p $end_dir
62-
cd $end_dir
63-
tar xvf $file
60+
echo " Found some logs in" "$file"
61+
echo "Will put it in " "$end_dir"
62+
mkdir -p "$end_dir"
63+
cd "$end_dir"||exit
64+
tar xvf "$file"
6465
fi

WFComplete_submitter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

33
echo "Executing $1 as cmst1..."
4-
sudo -u cmst1 /bin/bashs --init-file $1
4+
sudo -u cmst1 /bin/bashs --init-file "$1"

actcycle.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
BASE_DIR=/data/unified/WmAgentScripts/
2+
# shellcheck disable=SC2034
23
HTML_DIR=/var/www/html/unified/
34

4-
lock_name=`echo $BASH_SOURCE | cut -f 1 -d "."`.lock
5-
source $BASE_DIR/cycle_common.sh $lock_name
5+
# shellcheck disable=SC1090,SC2128
6+
lock_name=$(echo "$BASH_SOURCE" | cut -f 1 -d ".").lock
7+
# shellcheck disable=SC1090
8+
source $BASE_DIR/cycle_common.sh "$lock_name"
69

710
## get sso cookie and new grid proxy
11+
# shellcheck disable=SC1090
812
source $BASE_DIR/credentials.sh
913

1014
## submit ACDCs and clones from actions submitted via new recovery tools
1115
$BASE_DIR/cWrap.sh Unified/actor.py
1216

13-
rm -f $lock_name
17+
rm -f "$lock_name"
1418

assigncycle.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
BASE_DIR=/data/unified/WmAgentScripts/
2+
# shellcheck disable=SC2034
23
HTML_DIR=/var/www/html/unified/
34

4-
lock_name=`echo $BASH_SOURCE | cut -f 1 -d "."`.lock
5-
source $BASE_DIR/cycle_common.sh $lock_name
5+
# shellcheck disable=SC2128
6+
lock_name=$(echo "$BASH_SOURCE" | cut -f 1 -d ".").lock
7+
# shellcheck disable=SC1090
8+
source $BASE_DIR/cycle_common.sh "$lock_name"
69

710
## get the workflow in/out of the system
811
$BASE_DIR/cWrap.sh Unified/injector.py
@@ -26,5 +29,5 @@ $BASE_DIR/cWrap.sh Unified/assignor.py _PR_ref
2629
## assign the workflow to sites
2730
$BASE_DIR/cWrap.sh Unified/assignor.py
2831

29-
rm -f $lock_name
32+
rm -f "$lock_name"
3033

0 commit comments

Comments
 (0)