Пользователи создают скрипт из файла CSV

Используя информацию из ссылки LaunchPad выше и эту ссылку при установке / повторной установке Nvidia Primus, я смог повторно реализовать свои внешние мониторы. Этот ответ не является постоянным решением, а представляет собой подробное описание обходного пути, предложенного в выпуске LaunchPad.

В основном, я сделал следующее:

Очистил существующие драйверы Nvidia / связанные с Optimus пакеты:

sudo apt-get purge libvdpau-va-gl1 bumblebee* nvidia*

Снова установил: [!d4 ]

sudo apt-get install nvidia-331 nvidia-settings nvidia-prime

Загрузили и установили временные (обходные) пакеты с пониженным рейтингом:

sudo dpkg -i ubuntu-drivers-common_0.2.91.5_amd64.deb nvidia-common_0.2.91.5_amd64.deb 

Перезагрузили, установили мой BIOS в graphics card: Optimus и Optimus: enabled, и все было в порядке. Мне удалось обнаружить мой внешний монитор. Обратите внимание, что я все еще не могу использовать монитор ноутбука и внешний монитор вместе с переключением с Bumblebee на Primus, но по крайней мере у меня снова есть доступ к внешнему монитору.

3
задан 24 May 2018 в 09:24

3 ответа

Просто удалите самую последнюю строку в вашем скрипте (также это помогает сделать правильный отступ, чтобы увидеть ваши ошибки). Кроме того, вы забыли закончить свой последний цикл с помощью:

#!/bin/bash
filein="proyecto3.csv"
IFS=$'\n'

if [ ! -f "$filein" ]
then
    echo "Cannot find file $filein"
else
    groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
    fullnames=(`cut -d: -f 1 "$filein"`)
    userid=(`cut -d: -f 2 "$filein"`)
    usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)
fi

for group in ${groups[*]}
do
    grep -q "^$group" /etc/group ; let x=$?
    if [ $x -eq 1 ]
    then
        groupadd "$group"
    fi
done

x=0 #not sure why you reset x here to zero !?
created=0

for user in ${usernames[*]}
do
    useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null
    if [ $? -eq 0 ]
    then
        let created=$created+1
    fi
done

echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null
echo "Complete. $created accounts have been created."

До этого я действительно могу посоветовать вам использовать что-то вроде shellcheck на вашем скрипте (вы можете получить его из обычного Ubuntu все хранилища).

sudo apt update
sudo apt install shellcheck

Он выводит намного больше, что вы можете сделать лучше в своем скрипте:

$ shellcheck test.sh

In test.sh line 9:
    groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
            ^-- SC2006: Use $(..) instead of legacy `..`.


In test.sh line 10:
    fullnames=(`cut -d: -f 1 "$filein"`)
               ^-- SC2006: Use $(..) instead of legacy `..`.


In test.sh line 11:
    userid=(`cut -d: -f 2 "$filein"`)
    ^-- SC2034: userid appears unused. Verify it or export it.
            ^-- SC2006: Use $(..) instead of legacy `..`.


In test.sh line 12:
    usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)
               ^-- SC2006: Use $(..) instead of legacy `..`.
                                            ^-- SC2060: Quote parameters to tr to prevent glob expansion.
                                                  ^-- SC2060: Quote parameters to tr to prevent glob expansion.


In test.sh line 29:
    useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null
                  ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In test.sh line 30:
    if [ $? -eq 0 ]
         ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

В качестве альтернативы используйте онлайн-инструмент shellcheck ...

5
ответ дан 8 June 2018 в 13:59
  • 1
    голосуют за рекомендацию shellcheck. Хороший инструмент! – muclux 24 May 2018 в 10:54
  • 2
    @muclux Добро пожаловать. – Videonauth 24 May 2018 в 13:39
  • 3
    Здравствуйте, много тханка за советы, очень ценю. – Elio Basciani 25 May 2018 в 02:16
  • 4
    Если мой ответ решил вашу проблему, вы можете пометить его как принято, нажав на галочку рядом с ним. – Videonauth 25 May 2018 в 02:17
  • 5
    Да я знаю, но у меня еще есть проблема, и я собирался написать это в другом посте. – Elio Basciani 25 May 2018 в 02:19

Просто удалите самую последнюю строку в вашем скрипте (также это помогает сделать правильный отступ, чтобы увидеть ваши ошибки). Кроме того, вы забыли закончить свой последний цикл с помощью:

#!/bin/bash filein="proyecto3.csv" IFS=$'\n' if [ ! -f "$filein" ] then echo "Cannot find file $filein" else groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`) fullnames=(`cut -d: -f 1 "$filein"`) userid=(`cut -d: -f 2 "$filein"`) usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`) fi for group in ${groups[*]} do grep -q "^$group" /etc/group ; let x=$? if [ $x -eq 1 ] then groupadd "$group" fi done x=0 #not sure why you reset x here to zero !? created=0 for user in ${usernames[*]} do useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null if [ $? -eq 0 ] then let created=$created+1 fi done echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null echo "Complete. $created accounts have been created."

До этого я действительно могу посоветовать вам использовать что-то вроде shellcheck на вашем скрипте (вы можете получить его из обычного Ubuntu все хранилища).

sudo apt update sudo apt install shellcheck

Он выводит намного больше, что вы можете сделать лучше в своем скрипте:

$ shellcheck test.sh In test.sh line 9: groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`) ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 10: fullnames=(`cut -d: -f 1 "$filein"`) ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 11: userid=(`cut -d: -f 2 "$filein"`) ^-- SC2034: userid appears unused. Verify it or export it. ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 12: usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`) ^-- SC2006: Use $(..) instead of legacy `..`. ^-- SC2060: Quote parameters to tr to prevent glob expansion. ^-- SC2060: Quote parameters to tr to prevent glob expansion. In test.sh line 29: useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null ^-- SC2086: Double quote to prevent globbing and word splitting. ^-- SC2086: Double quote to prevent globbing and word splitting. In test.sh line 30: if [ $? -eq 0 ] ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

В качестве альтернативы используйте онлайн-инструмент shellcheck ...

5
ответ дан 17 July 2018 в 13:36

Просто удалите самую последнюю строку в вашем скрипте (также это помогает сделать правильный отступ, чтобы увидеть ваши ошибки). Кроме того, вы забыли закончить свой последний цикл с помощью:

#!/bin/bash filein="proyecto3.csv" IFS=$'\n' if [ ! -f "$filein" ] then echo "Cannot find file $filein" else groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`) fullnames=(`cut -d: -f 1 "$filein"`) userid=(`cut -d: -f 2 "$filein"`) usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`) fi for group in ${groups[*]} do grep -q "^$group" /etc/group ; let x=$? if [ $x -eq 1 ] then groupadd "$group" fi done x=0 #not sure why you reset x here to zero !? created=0 for user in ${usernames[*]} do useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null if [ $? -eq 0 ] then let created=$created+1 fi done echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null echo "Complete. $created accounts have been created."

До этого я действительно могу посоветовать вам использовать что-то вроде shellcheck на вашем скрипте (вы можете получить его из обычного Ubuntu все хранилища).

sudo apt update sudo apt install shellcheck

Он выводит намного больше, что вы можете сделать лучше в своем скрипте:

$ shellcheck test.sh In test.sh line 9: groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`) ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 10: fullnames=(`cut -d: -f 1 "$filein"`) ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 11: userid=(`cut -d: -f 2 "$filein"`) ^-- SC2034: userid appears unused. Verify it or export it. ^-- SC2006: Use $(..) instead of legacy `..`. In test.sh line 12: usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`) ^-- SC2006: Use $(..) instead of legacy `..`. ^-- SC2060: Quote parameters to tr to prevent glob expansion. ^-- SC2060: Quote parameters to tr to prevent glob expansion. In test.sh line 29: useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null ^-- SC2086: Double quote to prevent globbing and word splitting. ^-- SC2086: Double quote to prevent globbing and word splitting. In test.sh line 30: if [ $? -eq 0 ] ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

В качестве альтернативы используйте онлайн-инструмент shellcheck ...

5
ответ дан 20 July 2018 в 13:40

Другие вопросы по тегам:

Похожие вопросы: