Problems working a script
Posted: 05 Nov 2023 07:27
I'm tasked with making this script run flawlessly. Unfortunately, I'm a total newbie in this area. I'm supposed to find approximately 5 errors and display the correct answer:
The task is:
The following batch script contains (at least) five errors. List these errors and give a
brief explanation of how to fix them. Note that your answer should refer to the line
numbers below. The purpose of the script is to ask the user to input a directory
name, and then store some system information in that directory. The information
includes: the computer name; current date / time; the running processes; and the
current username.
The script is below, and my corrections would be: 1. Best practice in a script is to set @ECHO OFF
2. set /P directory="Results directory: "
3. No correction
4. echo %computername% > %directory%\hostname
5. net time \\%computername% < %directory%\time /t \date /t
6. net user > %directory%\query user
7. whoami > %directory%\whoami
8. tasklist > %directory%\tasklist
9. echo "Program complete"
10. ) ELSE
11. echo "Output directory not found"
12. )
1. @ECHO ON
2. set /X directory="Results directory: "
3. if not exist %directory% (
4. echo %computername% > %directory%\comp-name
5. net time \\%computername% < %directory%\start-time
6. net user > %directory%\users
7. whoami > %directory%\whoami
8. tasklist > %directory%\tasklist
9. echo Program complete
10. ) ELSE
11. echo Output directory not found
12. )
Its probably fairly easy, but I just cant crack it. Hope someone has the time to help me along, since I've been spending a lot of time on it.
Thank You, Tai
The task is:
The following batch script contains (at least) five errors. List these errors and give a
brief explanation of how to fix them. Note that your answer should refer to the line
numbers below. The purpose of the script is to ask the user to input a directory
name, and then store some system information in that directory. The information
includes: the computer name; current date / time; the running processes; and the
current username.
The script is below, and my corrections would be: 1. Best practice in a script is to set @ECHO OFF
2. set /P directory="Results directory: "
3. No correction
4. echo %computername% > %directory%\hostname
5. net time \\%computername% < %directory%\time /t \date /t
6. net user > %directory%\query user
7. whoami > %directory%\whoami
8. tasklist > %directory%\tasklist
9. echo "Program complete"
10. ) ELSE
11. echo "Output directory not found"
12. )
1. @ECHO ON
2. set /X directory="Results directory: "
3. if not exist %directory% (
4. echo %computername% > %directory%\comp-name
5. net time \\%computername% < %directory%\start-time
6. net user > %directory%\users
7. whoami > %directory%\whoami
8. tasklist > %directory%\tasklist
9. echo Program complete
10. ) ELSE
11. echo Output directory not found
12. )
Its probably fairly easy, but I just cant crack it. Hope someone has the time to help me along, since I've been spending a lot of time on it.
Thank You, Tai