C
C#9mo ago
Whiteboy

✅ Executing bash script in docker container with Docket.DotNet in ASP.NET website

So i need to run some script in docker container and the container crashes instantly and logs are:
bash: line 56: ./ExaminationFile.sh: cannot execute: required file not found
bash: line 56: ./ExaminationFile.sh: cannot execute: required file not found
I'm using Gcc:Latest docker image
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -l > lsOutput.txt && " +
$"pwd > pwdOutput.txt && " +
$"./ExaminationFile.sh > testCount.txt"
},
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -l > lsOutput.txt && " +
$"pwd > pwdOutput.txt && " +
$"./ExaminationFile.sh > testCount.txt"
},
The script:
#!/bin/bash

getNumTests() {
echo 5
}

getTestInput() {
local test_index=$1
case $test_index in
0) echo "5 10 8 15 3 6";;
1) echo "2 4 7 9 1";;
2) echo "10 20 30";;
3) echo "100 50 75";;
4) echo "3 6 9 12";;
*) echo "";;
esac
}

getMemoryTimeLimits() {
local test_index=$1
case $test_index in
0) echo "128 1000";;
1) echo "64 500";;
2) echo "256 1500";;
3) echo "512 2000";;
4) echo "32 300";;
*) echo "0 0";;
esac
}

getCorrectOutput() {
local test_index=$1
case $test_index in
0) echo "15";;
1) echo "9";;
2) echo "30";;
3) echo "100";;
4) echo "12";;
*) echo "0";;
esac
}

# Main script logic
if [[ $# -eq 0 ]]; then
getNumTests
elif [[ $1 == "P" && $# -eq 2 ]]; then
getMemoryTimeLimits $2
elif [[ $1 == "R" && $# -eq 2 ]]; then
getCorrectOutput $2
elif [[ $1 =~ ^[0-9]+$ ]]; then
getTestInput $1
else
echo "Invalid arguments"
exit 1
fi
#!/bin/bash

getNumTests() {
echo 5
}

getTestInput() {
local test_index=$1
case $test_index in
0) echo "5 10 8 15 3 6";;
1) echo "2 4 7 9 1";;
2) echo "10 20 30";;
3) echo "100 50 75";;
4) echo "3 6 9 12";;
*) echo "";;
esac
}

getMemoryTimeLimits() {
local test_index=$1
case $test_index in
0) echo "128 1000";;
1) echo "64 500";;
2) echo "256 1500";;
3) echo "512 2000";;
4) echo "32 300";;
*) echo "0 0";;
esac
}

getCorrectOutput() {
local test_index=$1
case $test_index in
0) echo "15";;
1) echo "9";;
2) echo "30";;
3) echo "100";;
4) echo "12";;
*) echo "0";;
esac
}

# Main script logic
if [[ $# -eq 0 ]]; then
getNumTests
elif [[ $1 == "P" && $# -eq 2 ]]; then
getMemoryTimeLimits $2
elif [[ $1 == "R" && $# -eq 2 ]]; then
getCorrectOutput $2
elif [[ $1 =~ ^[0-9]+$ ]]; then
getTestInput $1
else
echo "Invalid arguments"
exit 1
fi
No description
63 Replies
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
the file is literally copied from the container in the green area in the screen buf i will do this in a sec
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
No description
Whiteboy
WhiteboyOP9mo ago
is it different tho?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
ye
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
ah like this?
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd " +
$"./ExaminationFile.sh > testCount.txt"
},
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd " +
$"./ExaminationFile.sh > testCount.txt"
},
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
idk it's gcc:latest
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
No description
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
No description
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
the container crashes instantly
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
echo '{examinationFileAsString}' > ExaminationFile.sh &&
echo '{examinationFileAsString}' > ExaminationFile.sh &&
isn't this exactly that? im new to linux
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
so i just create a file? then copy the script?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
it's a whole project of something like coding portal and i do dcode execution and tests inside docker
Whiteboy
WhiteboyOP9mo ago
I don't get it
No description
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
AH
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
i see
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
#!/usr/bin/bash

getNumTests() {
echo 5
}



# Main script logic
if [[ $# -eq 0 ]]; then
getNumTests
else
echo "Invalid arguments"
exit 1
fi
#!/usr/bin/bash

getNumTests() {
echo 5
}



# Main script logic
if [[ $# -eq 0 ]]; then
getNumTests
else
echo "Invalid arguments"
exit 1
fi
ike this?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
a
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
2024-04-24 13:22:25 total 12K
2024-04-24 13:22:25 drwxr-xr-x 2 root root 4.0K Apr 24 11:22 .
2024-04-24 13:22:25 drwxr-xr-x 1 root root 4.0K Apr 24 11:22 ..
2024-04-24 13:22:25 -rwxrwxrwx 1 root root 26 Apr 24 11:22 ExaminationFile.sh
2024-04-24 13:22:25 #!/bin/bash
2024-04-24 13:22:25
2024-04-24 13:22:25 echo "foo"
2024-04-24 13:22:25 /myApp
2024-04-24 13:22:25 bash: line 3: ./ExaminationFile.sh: cannot execute: required file not found
2024-04-24 13:22:25 total 12K
2024-04-24 13:22:25 drwxr-xr-x 2 root root 4.0K Apr 24 11:22 .
2024-04-24 13:22:25 drwxr-xr-x 1 root root 4.0K Apr 24 11:22 ..
2024-04-24 13:22:25 -rwxrwxrwx 1 root root 26 Apr 24 11:22 ExaminationFile.sh
2024-04-24 13:22:25 #!/bin/bash
2024-04-24 13:22:25
2024-04-24 13:22:25 echo "foo"
2024-04-24 13:22:25 /myApp
2024-04-24 13:22:25 bash: line 3: ./ExaminationFile.sh: cannot execute: required file not found
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
No description
Whiteboy
WhiteboyOP9mo ago
to the script?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
2024-04-24 13:25:27 total 12K 2024-04-24 13:25:27 drwxr-xr-x 2 root root 4.0K Apr 24 11:25 . 2024-04-24 13:25:27 drwxr-xr-x 1 root root 4.0K Apr 24 11:25 .. 2024-04-24 13:25:27 -rwxrwxrwx 1 root root 26 Apr 24 11:25 ExaminationFile.sh 2024-04-24 13:25:27 #!/bin/bash 2024-04-24 13:25:27 2024-04-24 13:25:27 echo "foo" 2024-04-24 13:25:27 /myApp 2024-04-24 13:25:27 bash: line 3: hd: command not found
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
2024-04-24 13:26:25 total 12K 2024-04-24 13:26:25 drwxr-xr-x 2 root root 4.0K Apr 24 11:26 . 2024-04-24 13:26:25 drwxr-xr-x 1 root root 4.0K Apr 24 11:26 .. 2024-04-24 13:26:25 -rwxrwxrwx 1 root root 26 Apr 24 11:26 ExaminationFile.sh 2024-04-24 13:26:25 #!/bin/bash 2024-04-24 13:26:25 2024-04-24 13:26:25 echo "foo" 2024-04-24 13:26:25 /myApp 2024-04-24 13:26:25 bash: line 3: hexdump: command not found
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
well i can make simple method to fix this no?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString.Remove('\r')}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd &&" +
$"./ExaminationFile.sh > testCount.txt"
},
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString.Remove('\r')}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd &&" +
$"./ExaminationFile.sh > testCount.txt"
},
2024-04-24 13:29:07 total 12K 2024-04-24 13:29:07 drwxr-xr-x 2 root root 4.0K Apr 24 11:29 . 2024-04-24 13:29:07 drwxr-xr-x 1 root root 4.0K Apr 24 11:29 .. 2024-04-24 13:29:07 -rwxrwxrwx 1 root root 14 Apr 24 11:29 ExaminationFile.sh 2024-04-24 13:29:07 #!/bin/bash 2024-04-24 13:29:07 2024-04-24 13:29:07 /myApp 2024-04-24 13:29:07 bash: line 2: ./ExaminationFile.sh: cannot execute: required file not found
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
:kekw:
MODiX
MODiX9mo ago
TeBeCo
REPL Result: Success
"Foo\r\nbar".Replace("\r\n", "\n")
"Foo\r\nbar".Replace("\r\n", "\n")
Result: string
Foo
bar
Foo
bar
Compile: 275.269ms | Execution: 28.619ms | React with ❌ to remove this embed.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString.Replace("\r\n", "\n")}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd &&" +
$"./ExaminationFile.sh > testCount.txt"
},
Cmd = new List<string>
{
"bash",
"-c",
$"echo '{examinationFileAsString.Replace("\r\n", "\n")}' > ExaminationFile.sh && " +
$"chmod 777 ExaminationFile.sh && " +
$"ls -alh && " +
$"cat ./ExaminationFile.sh && " +
$"pwd &&" +
$"./ExaminationFile.sh > testCount.txt"
},
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
2024-04-24 13:31:42 total 12K 2024-04-24 13:31:42 drwxr-xr-x 2 root root 4.0K Apr 24 11:31 . 2024-04-24 13:31:42 drwxr-xr-x 1 root root 4.0K Apr 24 11:31 .. 2024-04-24 13:31:42 -rwxrwxrwx 1 root root 24 Apr 24 11:31 ExaminationFile.sh 2024-04-24 13:31:42 #!/bin/bash 2024-04-24 13:31:42 2024-04-24 13:31:42 echo "foo" 2024-04-24 13:31:42 /myApp BRO I LOVE YOU I WAS STUCK ON THIS FOR A WEEK
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
No description
Whiteboy
WhiteboyOP9mo ago
it did
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Whiteboy
WhiteboyOP9mo ago
it wil ltets whole case and see if all works but i guess it will now
Whiteboy
WhiteboyOP9mo ago
No description
Whiteboy
WhiteboyOP9mo ago
it executes tho TL:DR
.Replace("\r\n", "\n")
.Replace("\r\n", "\n")
Fixed issue of copying file as string to linux
Want results from more Discord servers?
Add your server