benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf e1c91063-3bca-57d6-904d-69642f4ba5b1
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import subprocess
import os
import json
from datetime import datetime
def task_func(script_name='backup.sh', log_file='/home/user/backup_log.json'):
"""
Runs the provided backup shell script and logs the start time, end time, and exit status
in a specified JSON log file.
Parameters:
- script_name (str): The name of the shell script to run. Default is 'backup.sh'.
- log_file (str): The path to the JSON log file where the execution details will be recorded. Default is '/home/user/backup_log.json'.
Returns:
dict: A dictionary containing:
- 'start_time': The start time of the script execution in the format '%Y-%m-%d %H:%M:%S'.
- 'end_time': The end time of the script execution in the format '%Y-%m-%d %H:%M:%S'.
- 'exit_status': The exit status of the script execution (0 for success, other values indicate an error).
Raises:
- FileNotFoundError: If the script file does not exist.
- RuntimeError: If there is an error executing the script.
Requirements:
- subprocess
- os
- datetime
- json
Example:
>>> task_func()
{'start_time': '2023-09-19 14:30:00', 'end_time': '2023-09-19 14:35:00', 'exit_status': 0}
"""
instruct prompt
Runs the provided backup shell script and logs the start time, end time, and exit status in a specified JSON log file.
The function should raise the exception for: FileNotFoundError: If the script file does not exist. RuntimeError: If there is an error executing the script.
The function should output with:
dict: A dictionary containing:
'start_time': The start time of the script execution in the format '%Y-%m-%d %H:%M:%S'.
'end_time': The end time of the script execution in the format '%Y-%m-%d %H:%M:%S'.
'exit_status': The exit status of the script execution (0 for success, other values indicate an error).
You should write self-contained code starting with:
Code
import subprocess
import os
import json
from datetime import datetime
def task_func(script_name='backup.sh', log_file='/home/user/backup_log.json'):
code prompt
Code
import subprocess
import os
import json
from datetime import datetime
def task_func(script_name='backup.sh', log_file='/home/user/backup_log.json'):
entry point
task_func
libs
- subprocess
- datetime
- json
- os
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import