nan0s7 / nfancurve

A small and lightweight POSIX script for using a custom fan curve in Linux for those with an Nvidia GPU.
GNU General Public License v3.0
314 stars 57 forks source link

146 Syntax error: redirection unexpected #47

Closed qq1090942722 closed 2 years ago

qq1090942722 commented 2 years ago

I simply download the code and run ./temp.sh , it shows this line ./temp.sh: 146: Syntax error: redirection unexpected. This is a Ubuntu 20.04 machine. And I use ./temp.sh -v .It shows Version 19.4

I tested on another centos7 machine and it works fine... Can you help me. Thanks!

nan0s7 commented 2 years ago

Hmm not sure why it's not working on Ubuntu specifically. This may happen when Coolbits aren't enabled, but I assumed you've done that properly if it works on centos.

You could try using a different shell; sh temp.sh or install dash and use dash temp.sh.

You can also run it in logging mode using the -l option; ./temp.sh -l and send me the output here after a few seconds of it running (if it runs at all).

I assume you're using the same config file between the two OS's?

If you're using the latest pull from the source, try the one prior to adding a new feature as the latest one may not have been tested enough.

qq1090942722 commented 2 years ago

Maybe it is due to the format of the file? See the mp4 movie. When I comment on the line which gives the error, the line below change in color...  And if I delete that line, the script can execute, but shows more bug...like the picture... I am new to bash script...Please forgive me....

 

------------------ 原始邮件 ------------------ 发件人: "nan0s7/nfancurve" @.>; 发送时间: 2021年12月10日(星期五) 下午3:41 @.>; @.**@.>; 主题: Re: [nan0s7/nfancurve] 146 Syntax error: redirection unexpected (Issue #47)

Hmm not sure why it's not working on Ubuntu specifically. This may happen when Coolbits aren't enabled, but I assumed you've done that properly if it works on centos.

You could try using a different shell; sh temp.sh or install dash and use dash temp.sh.

You can also run it in logging mode using the -l option; ./temp.sh -l and send me the output here after a few seconds of it running (if it runs at all).

I assume you're using the same config file between the two OS's?

If you're using the latest pull from the source, try the one prior to adding a new feature as the latest one may not have been tested enough.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

EthanDarling8 commented 2 years ago

It's doing the same thing for me. I'm running Ubuntu 21.10 and as soon as I run ./temp.sh it gives the same error. Same nfancurve version and coolbits has been enabled. After running ./temp.sh -l it doesn't run and no logs are shown nor log file generated. If there is anymore info that I can provide let me know. This did not happen to me on Ubuntu 20.04 and this week I did a fresh install of Ubuntu 21.10 and it suddenly isn't working anymore.

sicknesz commented 2 years ago

I got it working by editing line 146 to only have two << sign not <<< seems to works, but it get the same error as previously (unrelated) : ERROR: Error assigning value 55 to attribute 'GPUTargetFanSpeed' (desktop:0[fan:0]) as specified in assignment '[fan:0]/GPUTargetFanSpeed=55' (Unknown Error).

nan0s7 commented 2 years ago

@EthanDarling8 @sicknesz have either of you tried the previous committed version? Line 146 impliments an experimental change committed by someone other than myself, so I haven't looked over it closely. It does add another dependency so it could be missing from the default Ubuntu installation or some similar error. However, I don't see why it should cause any issues if it is disabled in the config file.

Nonetheless, try this version: https://github.com/nan0s7/nfancurve/tree/ed631f01c4ab7b0720e82e82943298b5b3b511f5

The error @sicknesz mentioned seems to be caused by either CoolBits or the fan control state not being enabled to 1. Unless NVIDIA changed the command to change the fan speed.

Although I am busy with work IRL, I may get the chance to boot up an Ubuntu derived distro and test things out. Although I will point out these issues can arise from not having a proper X display connected and running. I don't know how Wayland handles things.

sicknesz commented 2 years ago

@nan0s7 : the version you asked me to try works perfectly fine, thanks.

$ ./temp.sh    
################################################################################
#          nan0s7's script for automatically managing GPU fan speed            #
################################################################################

Configuration file: /home/owner/nfancurve/config
Number of Fans detected: 
1
Number of GPUs detected: 
1

  Attribute 'GPUFanControlState' (desktop:0[gpu:0]) assigned value 1.

Started process for 1 GPU and 1 Fan

  Attribute 'GPUTargetFanSpeed' (desktop:0[fan:0]) assigned value 55.

  Attribute 'GPUFanControlState' (desktop:0[gpu:0]) assigned value 0.
jorisgr commented 2 years ago

The problem seems to be due to recent additions using bash-code that isn't portable to dash (the standard Debian/Ubuntu /bin/sh). More specifically it uses '[[' test constructs which don't seem to be POSIX-compliant (see e.g. this ubuntu wiki page).

A current workaround can be to execute the script with bash (e.g. change the shebang to #!/bin/bash), but better would be to replace the tests with single bracket-versions. More semantic changes are needed than just finding and replacing the double brackets with single ones, but I haven't figured out yet which ones.

nan0s7 commented 2 years ago

The problem seems to be due to recent additions using bash-code that isn't portable to dash (the standard Debian/Ubuntu /bin/sh). More specifically it uses '[[' test constructs which don't seem to be POSIX-compliant (see e.g. this ubuntu wiki page).

A current workaround can be to execute the script with bash (e.g. change the shebang to #!/bin/bash), but better would be to replace the tests with single bracket-versions. More semantic changes are needed than just finding and replacing the double brackets with single ones, but I haven't figured out yet which ones.

Yeah I suspected as much. When I have the spare time I will definitely rewrite it using the POSIX standard. I'll find a way to integrate it better with the rest of the code as well. There is still much to improve on.

Thanks for the workaround for those who want to run it in the meantime!

Zaczero commented 2 years ago

FOR THE SHEBANG WORKAROUND

In addition to changing the shebang (from #!/bin/sh to #!/bin/bash), make sure to update the nfancurve.service file, which, as it is currently, always executes the script with /bin/sh.

Old line:

ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf

Fixed line:

ExecStart=/usr/bin/nfancurve -c /etc/nfancurve.conf
nan0s7 commented 2 years ago

I've removed any of the newer bits of code that do not comply with POSIX standards. I've also applied the above edit to the service file which should reduce compatability issues, if it was ever a problem with the original code.