script .sh not working as expected/What am I doing wrong?

chlowjow

New Member
Mar 25, 2024
23
0
1
Hello People,

I am a newbie to proxmox and to Linux/Ubuntu in general.
I want to execute a script by Proxmox after reboot but it is not working.
The script needs to SSH into ILO4 (HP server) and adjust the fan value's.

I have attached my script and the errors it is giving me.
Looks like basic knowlegde is crucial, tried for many hours now and cannot seem to find out what is going wrong with the script.

Can somebody help me please?

Thanks in advance!!!
 

Attachments

  • script error.JPG
    script error.JPG
    115 KB · Views: 14
  • sriptnotworking.JPG
    sriptnotworking.JPG
    105.7 KB · Views: 14
Did you edit that script in an editor on a Mac?

When editing a script make sure to use an editor like notepad++ that allows you to set the line endings to "Unix(LF)" instead of "Windows(CR+LF)" or "Mac(CR)".
 
  • Like
Reactions: chlowjow
Thanks for your advise guys. I made the script on Windows....to be honest, I copied most of it and changed it.
I will try to convert it or otherwise create it in Linux.
But to be sure: in the script itself nothing is wrong? I mean, all possible commands must work in this way? And also the asterix at /bin/bash needs it to be there or do I need to remove this?
 
But to be sure: in the script itself nothing is wrong? I mean, all possible commands must work in this way?
it looks fine at quick glance
And also the asterix at /bin/bash needs it to be there or do I need to remove this?
dont remove it and follow the instructions at the bottom, but not literally - adjust path as needed.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
I have installed Notepad ++, copied text to it, changed it to Unix (LF) and uploaded it again to Proxmox through FTP.
Looks like the script is actually executing now.
But......Still have an error in it:

1. When I add /usr/bin/sshpass (as mentioned above) I get: No such file or directory
2. When I change it to sshpass only I get: command not found

Please see attached files.
Can somebody tell me what is wrong with this line?
 

Attachments

  • script error.JPG
    script error.JPG
    19.6 KB · Views: 4
  • sriptnotworking.JPG
    sriptnotworking.JPG
    100.6 KB · Views: 4
You can find the path via : which sshpass
Did you run this command? ^

Regardless, it sounds like you did not install sshpass. Its not part of default installation.

https://stackoverflow.com/questions/38129835/sshpass-command-not-found-error

In addition you broke the script in a new way.. You now have line 14 and line 15 as two distinct lines. It should be one single line.
One way to solve it is to add " \" at the end of line 14.

Perhaps you should get one of the books referenced here or elsewhere: https://www.reddit.com/r/bash/comments/rpihj2/scripting_and_best_practices_book/


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
  • Like
Reactions: chlowjow
Did you run this command? ^

Regardless, it sounds like you did not install sshpass. Its not part of default installation.

https://stackoverflow.com/questions/38129835/sshpass-command-not-found-error

In addition you broke the script in a new way.. You now have line 14 and line 15 as two distinct lines. It should be one single line.
One way to solve it is to add " \" at the end of line 14.

Perhaps you should get one of the books referenced here or elsewhere: https://www.reddit.com/r/bash/comments/rpihj2/scripting_and_best_practices_book/


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

I did indeed not install sshpass...... thought it was a integrated command, (something with basic knowledge....:)

Thanks!, will try that first and now I understand the path to it is important.

Thanks for your patience...and help
 
have you tried regular open ssh from PVE host ?
because, iirc, physical NIC can't access iLO dedicated NIC
 
I wanted to report back that I have installed SSH to proxmox and the script was running with the next error: acces denied. So I was very happy that the script does function now!!

I resolved this problem to remove the single quotes at the script were it says ‘password’.

That’s a little confusing for me because I read somewhere that it was critical to enter the password in the script with single quotes.

But hey, it’s working!!
Next challenge is to get it to execute with cron.

Thanks for the help!
 
I wanted to report back that I have installed SSH to proxmox and the script was running with the next error: acces denied. So I was very happy that the script does function now!!

I resolved this problem to remove the single quotes at the script were it says ‘password’.

That’s a little confusing for me because I read somewhere that it was critical to enter the password in the script with single quotes.

But hey, it’s working!!
Next challenge is to get it to execute with cron.

Thanks for the help!
If you want your script to run once on boot, consider using a oneshot systemd unit over cron. Cron won’t let you schedule something to run once on boot (but it will let you run it, say, once every hour)
 
Last edited:
  • Like
Reactions: bri
I resolved this problem to remove the single quotes at the script were it says ‘password’.

That’s a little confusing for me because I read somewhere that it was critical to enter the password in the script with single quotes.
This is because you used "wrong" single quotes.
As you can see in screenshot you used 0x91 character vs 0x27

0x91 is 145 decimal. “‘ 145 ‘ left single quotation mark”
chars.JPG
It was interpreted by Shell as something it should execute (inside these specific chars).


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Last edited:
This is because you used "wrong" single quotes.
As you can see in screenshot you used 0x91 character vs 0x27

0x91 is 145 decimal. “‘ 145 ‘ left single quotation mark”
View attachment 65287
It was interpreted by Shell as something it should execute (inside these specific chars).


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

Thank you very much for this clarification! At this way I will never make this mistake again....
 
Allright, the script is running. I checked it, when I execute it on command line it makes the needed changes to the ILO4 Fans.
Now I have added it to cron.

I want to test it first because when I restart the server, nothing happens, so something is wrong.
I read somewhere that you can force cron to execute tasks with "run-parts /etc/cron.daily"
When I execute it, it does not give me an error but it also is not giving me feedback that it is executed, it that makes sense.
But when ( I think) it is executed I check in ILO4 and it didn't make changes.

This is my crontab line:

@reboot root /bin/bash .local/share/script/fan_script.sh > /dev/null 2>&1

Can somebody tell me what I am missing here?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!