fix stderr output to file
This commit is contained in:
parent
e4454f77c2
commit
c9e50f28d9
25
script
25
script
@ -40,6 +40,24 @@ list_processes() {
|
||||
ps -eo pid,comm --sort=pid
|
||||
}
|
||||
|
||||
# Ручная обработка аргументов для раннего перенаправления
|
||||
for ((i = 1; i <= $#; i++)); do
|
||||
if [[ ${!i} == "-e" ]]; then
|
||||
next=$((i + 1))
|
||||
ERR_FILE=${!next}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Настройка вывода ошибок
|
||||
if [[ -n "$ERR_FILE" ]]; then
|
||||
if ! check_path "$ERR_FILE"; then
|
||||
exit 1
|
||||
fi
|
||||
echo "Redirecting errors to $ERR_FILE" >&2
|
||||
exec 2>"$ERR_FILE"
|
||||
fi
|
||||
|
||||
# Парсинг аргументов через getopts
|
||||
while getopts ":hupl:e:" opt; do
|
||||
case "$opt" in
|
||||
@ -81,13 +99,6 @@ main() {
|
||||
exec 1>"$LOG_FILE"
|
||||
fi
|
||||
|
||||
if [[ -n "$ERR_FILE" ]]; then
|
||||
if ! check_path "$ERR_FILE"; then
|
||||
exit 1
|
||||
fi
|
||||
exec 2>"$ERR_FILE"
|
||||
fi
|
||||
|
||||
# Выполнение запрошенных действий
|
||||
if [[ $SHOW_USERS -eq 1 && $SHOW_PROCESSES -eq 1 ]]; then
|
||||
echo "Error: Cannot use both -u and -p options simultaneously." >&2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user